image/qpixmapcache.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3static int cache_limit = 10240; -
4QPixmapCache::Key::Key() : d(0) -
5{ -
6}
executed: }
Execution Count:6224
6224
7 -
8 -
9 -
10 -
11 -
12QPixmapCache::Key::Key(const Key &other) -
13{ -
14 if (other.d)
partially evaluated: other.d
TRUEFALSE
yes
Evaluation Count:16956
no
Evaluation Count:0
0-16956
15 ++(other.d->ref);
executed: ++(other.d->ref);
Execution Count:16956
16956
16 d = other.d; -
17}
executed: }
Execution Count:16956
16956
18 -
19 -
20 -
21 -
22QPixmapCache::Key::~Key() -
23{ -
24 if (d && --(d->ref) == 0)
evaluated: d
TRUEFALSE
yes
Evaluation Count:20058
yes
Evaluation Count:3115
evaluated: --(d->ref) == 0
TRUEFALSE
yes
Evaluation Count:1544
yes
Evaluation Count:18514
1544-20058
25 delete d;
executed: delete d;
Execution Count:1544
1544
26}
executed: }
Execution Count:23173
23173
27 -
28 -
29 -
30 -
31 -
32 -
33 -
34bool QPixmapCache::Key::operator ==(const Key &key) const -
35{ -
36 return (d == key.d);
executed: return (d == key.d);
Execution Count:10964
10964
37} -
38QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other) -
39{ -
40 if (d != other.d) {
partially evaluated: d != other.d
TRUEFALSE
yes
Evaluation Count:1558
no
Evaluation Count:0
0-1558
41 if (other.d)
partially evaluated: other.d
TRUEFALSE
yes
Evaluation Count:1558
no
Evaluation Count:0
0-1558
42 ++(other.d->ref);
executed: ++(other.d->ref);
Execution Count:1558
1558
43 if (d && --(d->ref) == 0)
evaluated: d
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1550
partially evaluated: --(d->ref) == 0
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-1550
44 delete d;
executed: delete d;
Execution Count:8
8
45 d = other.d; -
46 }
executed: }
Execution Count:1558
1558
47 return *this;
executed: return *this;
Execution Count:1558
1558
48} -
49 -
50class QPMCache : public QObject, public QCache<QPixmapCache::Key, QPixmapCacheEntry> -
51{ -
52 public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; -
53public: -
54 QPMCache(); -
55 ~QPMCache(); -
56 -
57 void timerEvent(QTimerEvent *); -
58 bool insert(const QString& key, const QPixmap &pixmap, int cost); -
59 QPixmapCache::Key insert(const QPixmap &pixmap, int cost); -
60 bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost); -
61 bool remove(const QString &key); -
62 bool remove(const QPixmapCache::Key &key); -
63 -
64 void resizeKeyArray(int size); -
65 QPixmapCache::Key createKey(); -
66 void releaseKey(const QPixmapCache::Key &key); -
67 void clear(); -
68 -
69 QPixmap *object(const QString &key) const; -
70 QPixmap *object(const QPixmapCache::Key &key) const; -
71 -
72 static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key) -
73 {return key.d;}
executed: return key.d;
Execution Count:14112
14112
74 -
75 static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key); -
76 -
77 QList< QPair<QString,QPixmap> > allPixmaps() const; -
78 bool flushDetachedPixmaps(bool nt); -
79 -
80private: -
81 enum { soon_time = 10000, flush_time = 30000 }; -
82 int *keyArray; -
83 int theid; -
84 int ps; -
85 int keyArraySize; -
86 int freeKey; -
87 QHash<QString, QPixmapCache::Key> cacheKeys; -
88 bool t; -
89}; -
90 -
91 -
92 -
93 -
94uint qHash(const QPixmapCache::Key &k) -
95{ -
96 return qHash(QPMCache::get(k)->key);
executed: return qHash(QPMCache::get(k)->key);
Execution Count:14112
14112
97} -
98 -
99QPMCache::QPMCache() -
100 : QObject(0), -
101 QCache<QPixmapCache::Key, QPixmapCacheEntry>(cache_limit * 1024), -
102 keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false) -
103{ -
104}
executed: }
Execution Count:185
185
105QPMCache::~QPMCache() -
106{ -
107 clear(); -
108 free(keyArray); -
109}
executed: }
Execution Count:185
185
110bool QPMCache::flushDetachedPixmaps(bool nt) -
111{ -
112 int mc = maxCost(); -
113 setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1); -
114 setMaxCost(mc); -
115 ps = totalCost(); -
116 -
117 bool any = false; -
118 QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin(); -
119 while (it != cacheKeys.end()) {
evaluated: it != cacheKeys.end()
TRUEFALSE
yes
Evaluation Count:163
yes
Evaluation Count:6
6-163
120 if (!contains(it.value())) {
evaluated: !contains(it.value())
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:157
6-157
121 releaseKey(it.value()); -
122 it = cacheKeys.erase(it); -
123 any = true; -
124 } else {
executed: }
Execution Count:6
6
125 ++it; -
126 }
executed: }
Execution Count:157
157
127 } -
128 -
129 return any;
executed: return any;
Execution Count:6
6
130} -
131 -
132void QPMCache::timerEvent(QTimerEvent *) -
133{ -
134 bool nt = totalCost() == ps; -
135 if (!flushDetachedPixmaps(nt)) {
partially evaluated: !flushDetachedPixmaps(nt)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
136 killTimer(theid); -
137 theid = 0; -
138 } else if (nt != t) {
never executed: }
partially evaluated: nt != t
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
139 killTimer(theid); -
140 theid = startTimer(nt ? soon_time : flush_time); -
141 t = nt; -
142 }
never executed: }
0
143} -
144 -
145 -
146QPixmap *QPMCache::object(const QString &key) const -
147{ -
148 QPixmapCache::Key cacheKey = cacheKeys.value(key); -
149 if (!cacheKey.d || !cacheKey.d->isValid) {
evaluated: !cacheKey.d
TRUEFALSE
yes
Evaluation Count:1562
yes
Evaluation Count:10764
partially evaluated: !cacheKey.d->isValid
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10764
0-10764
150 const_cast<QPMCache *>(this)->cacheKeys.remove(key); -
151 return 0;
executed: return 0;
Execution Count:1562
1562
152 } -
153 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(cacheKey); -
154 -
155 if (!ptr) {
partially evaluated: !ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10764
0-10764
156 const_cast<QPMCache *>(this)->cacheKeys.remove(key); -
157 }
never executed: }
0
158 return ptr;
executed: return ptr;
Execution Count:10764
10764
159} -
160 -
161QPixmap *QPMCache::object(const QPixmapCache::Key &key) const -
162{ -
163 qt_noop(); -
164 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(key); -
165 -
166 if (!ptr)
partially evaluated: !ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
167 const_cast<QPMCache *>(this)->releaseKey(key);
never executed: const_cast<QPMCache *>(this)->releaseKey(key);
0
168 return ptr;
executed: return ptr;
Execution Count:9
9
169} -
170 -
171bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) -
172{ -
173 QPixmapCache::Key cacheKey; -
174 QPixmapCache::Key oldCacheKey = cacheKeys.value(key); -
175 -
176 if (oldCacheKey.d) {
partially evaluated: oldCacheKey.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1538
0-1538
177 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey); -
178 cacheKeys.remove(key); -
179 }
never executed: }
0
180 -
181 -
182 cacheKey = createKey(); -
183 -
184 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); -
185 if (success) {
partially evaluated: success
TRUEFALSE
yes
Evaluation Count:1538
no
Evaluation Count:0
0-1538
186 cacheKeys.insert(key, cacheKey); -
187 if (!theid) {
evaluated: !theid
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:1492
46-1492
188 theid = startTimer(flush_time); -
189 t = false; -
190 }
executed: }
Execution Count:46
46
191 } else {
executed: }
Execution Count:1538
1538
192 -
193 releaseKey(cacheKey); -
194 }
never executed: }
0
195 return success;
executed: return success;
Execution Count:1538
1538
196} -
197 -
198QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) -
199{ -
200 QPixmapCache::Key cacheKey = createKey(); -
201 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); -
202 if (success) {
partially evaluated: success
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
0-20
203 if (!theid) {
evaluated: !theid
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:18
2-18
204 theid = startTimer(flush_time); -
205 t = false; -
206 }
executed: }
Execution Count:2
2
207 } else {
executed: }
Execution Count:20
20
208 -
209 releaseKey(cacheKey); -
210 }
never executed: }
0
211 return cacheKey;
executed: return cacheKey;
Execution Count:20
20
212} -
213 -
214bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost) -
215{ -
216 qt_noop(); -
217 -
218 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key); -
219 -
220 QPixmapCache::Key cacheKey = createKey(); -
221 -
222 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); -
223 if (success) {
never evaluated: success
0
224 if(!theid) {
never evaluated: !theid
0
225 theid = startTimer(flush_time); -
226 t = false; -
227 }
never executed: }
0
228 const_cast<QPixmapCache::Key&>(key) = cacheKey; -
229 } else {
never executed: }
0
230 -
231 releaseKey(cacheKey); -
232 }
never executed: }
0
233 return success;
never executed: return success;
0
234} -
235 -
236bool QPMCache::remove(const QString &key) -
237{ -
238 QPixmapCache::Key cacheKey = cacheKeys.value(key); -
239 -
240 if (!cacheKey.d)
never evaluated: !cacheKey.d
0
241 return false;
never executed: return false;
0
242 cacheKeys.remove(key); -
243 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
0
244} -
245 -
246bool QPMCache::remove(const QPixmapCache::Key &key) -
247{ -
248 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
Execution Count:14
14
249} -
250 -
251void QPMCache::resizeKeyArray(int size) -
252{ -
253 if (size <= keyArraySize || size == 0)
partially evaluated: size <= keyArraySize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:166
partially evaluated: size == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:166
0-166
254 return;
never executed: return;
0
255 keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray, -
256 size * sizeof(int)))); -
257 for (int i = keyArraySize; i != size; ++i)
evaluated: i != size
TRUEFALSE
yes
Evaluation Count:1994
yes
Evaluation Count:166
166-1994
258 keyArray[i] = i + 1;
executed: keyArray[i] = i + 1;
Execution Count:1994
1994
259 keyArraySize = size; -
260}
executed: }
Execution Count:166
166
261 -
262QPixmapCache::Key QPMCache::createKey() -
263{ -
264 if (freeKey == keyArraySize)
evaluated: freeKey == keyArraySize
TRUEFALSE
yes
Evaluation Count:166
yes
Evaluation Count:1392
166-1392
265 resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
executed: resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
Execution Count:166
166
266 int id = freeKey; -
267 freeKey = keyArray[id]; -
268 QPixmapCache::Key key; -
269 QPixmapCache::KeyData *d = QPMCache::getKeyData(&key); -
270 d->key = ++id; -
271 return key;
executed: return key;
Execution Count:1558
1558
272} -
273 -
274void QPMCache::releaseKey(const QPixmapCache::Key &key) -
275{ -
276 if (key.d->key > keyArraySize || key.d->key <= 0)
evaluated: key.d->key > keyArraySize
TRUEFALSE
yes
Evaluation Count:1538
yes
Evaluation Count:26
evaluated: key.d->key <= 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:20
6-1538
277 return;
executed: return;
Execution Count:1544
1544
278 key.d->key--; -
279 keyArray[key.d->key] = freeKey; -
280 freeKey = key.d->key; -
281 key.d->isValid = false; -
282 key.d->key = 0; -
283}
executed: }
Execution Count:20
20
284 -
285void QPMCache::clear() -
286{ -
287 free(keyArray); -
288 keyArray = 0; -
289 freeKey = 0; -
290 keyArraySize = 0; -
291 -
292 QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QPixmapCacheEntry>::keys(); -
293 for (int i = 0; i < keys.size(); ++i)
evaluated: i < keys.size()
TRUEFALSE
yes
Evaluation Count:1538
yes
Evaluation Count:685
685-1538
294 keys.at(i).d->isValid = false;
executed: keys.at(i).d->isValid = false;
Execution Count:1538
1538
295 QCache<QPixmapCache::Key, QPixmapCacheEntry>::clear(); -
296}
executed: }
Execution Count:685
685
297 -
298QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key) -
299{ -
300 if (!key->d)
partially evaluated: !key->d
TRUEFALSE
yes
Evaluation Count:1558
no
Evaluation Count:0
0-1558
301 key->d = new QPixmapCache::KeyData;
executed: key->d = new QPixmapCache::KeyData;
Execution Count:1558
1558
302 return key->d;
executed: return key->d;
Execution Count:1558
1558
303} -
304 -
305QList< QPair<QString,QPixmap> > QPMCache::allPixmaps() const -
306{ -
307 QList< QPair<QString,QPixmap> > r; -
308 QHash<QString, QPixmapCache::Key>::const_iterator it = cacheKeys.begin(); -
309 while (it != cacheKeys.end()) {
never evaluated: it != cacheKeys.end()
0
310 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(it.value()); -
311 if (ptr)
never evaluated: ptr
0
312 r.append(QPair<QString,QPixmap>(it.key(),*ptr));
never executed: r.append(QPair<QString,QPixmap>(it.key(),*ptr));
0
313 ++it; -
314 }
never executed: }
0
315 return r;
never executed: return r;
0
316} -
317 -
318 -
319static QPMCache *pm_cache() { static QGlobalStatic<QPMCache > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QPMCache *x = new QPMCache; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QPMCache > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:185
yes
Evaluation Count:15780
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:185
no
Evaluation Count:0
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:15965
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:185
0-15965
320 -
321int q_QPixmapCache_keyHashSize() -
322{ -
323 return pm_cache()->size();
never executed: return pm_cache()->size();
0
324} -
325 -
326QPixmapCacheEntry::~QPixmapCacheEntry() -
327{ -
328 pm_cache()->releaseKey(key); -
329}
executed: }
Execution Count:1558
1558
330QPixmap *QPixmapCache::find(const QString &key) -
331{ -
332 return pm_cache()->object(key);
executed: return pm_cache()->object(key);
Execution Count:6
6
333} -
334bool QPixmapCache::find(const QString &key, QPixmap& pixmap) -
335{ -
336 return find(key, &pixmap);
executed: return find(key, &pixmap);
Execution Count:10614
10614
337} -
338bool QPixmapCache::find(const QString &key, QPixmap* pixmap) -
339{ -
340 QPixmap *ptr = pm_cache()->object(key); -
341 if (ptr && pixmap)
evaluated: ptr
TRUEFALSE
yes
Evaluation Count:10761
yes
Evaluation Count:1559
partially evaluated: pixmap
TRUEFALSE
yes
Evaluation Count:10761
no
Evaluation Count:0
0-10761
342 *pixmap = *ptr;
executed: *pixmap = *ptr;
Execution Count:10761
10761
343 return ptr != 0;
executed: return ptr != 0;
Execution Count:12320
12320
344} -
345bool QPixmapCache::find(const Key &key, QPixmap* pixmap) -
346{ -
347 -
348 if (!key.d || !key.d->isValid)
evaluated: !key.d
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:13
evaluated: !key.d->isValid
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:9
4-15
349 return false;
executed: return false;
Execution Count:19
19
350 QPixmap *ptr = pm_cache()->object(key); -
351 if (ptr && pixmap)
partially evaluated: ptr
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
partially evaluated: pixmap
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
352 *pixmap = *ptr;
executed: *pixmap = *ptr;
Execution Count:9
9
353 return ptr != 0;
executed: return ptr != 0;
Execution Count:9
9
354} -
355bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap) -
356{ -
357 return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
executed: return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
Execution Count:1538
1538
358} -
359QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap) -
360{ -
361 return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
executed: return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
Execution Count:20
20
362} -
363bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap) -
364{ -
365 -
366 if (!key.d || !key.d->isValid)
never evaluated: !key.d
never evaluated: !key.d->isValid
0
367 return false;
never executed: return false;
0
368 return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
369} -
370int QPixmapCache::cacheLimit() -
371{ -
372 return cache_limit;
executed: return cache_limit;
Execution Count:3
3
373} -
374void QPixmapCache::setCacheLimit(int n) -
375{ -
376 cache_limit = n; -
377 pm_cache()->setMaxCost(1024 * cache_limit); -
378}
never executed: }
0
379 -
380 -
381 -
382 -
383void QPixmapCache::remove(const QString &key) -
384{ -
385 pm_cache()->remove(key); -
386}
never executed: }
0
387 -
388 -
389 -
390 -
391 -
392 -
393 -
394void QPixmapCache::remove(const Key &key) -
395{ -
396 -
397 if (!key.d || !key.d->isValid)
evaluated: !key.d
TRUEFALSE
yes
Evaluation Count:115
yes
Evaluation Count:28
evaluated: !key.d->isValid
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:14
14-115
398 return;
executed: return;
Execution Count:129
129
399 pm_cache()->remove(key); -
400}
executed: }
Execution Count:14
14
401 -
402 -
403 -
404 -
405 -
406void QPixmapCache::clear() -
407{ -
408 if (true) {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:500
no
Evaluation Count:0
0-500
409 pm_cache()->clear(); -
410 } else {
executed: }
Execution Count:500
500
411 -
412 -
413 }
never executed: }
0
414} -
415 -
416void QPixmapCache::flushDetachedPixmaps() -
417{ -
418 pm_cache()->flushDetachedPixmaps(true); -
419}
never executed: }
0
420 -
421int QPixmapCache::totalUsed() -
422{ -
423 return (pm_cache()->totalCost()+1023) / 1024;
never executed: return (pm_cache()->totalCost()+1023) / 1024;
0
424} -
425 -
426QList< QPair<QString,QPixmap> > QPixmapCache::allPixmaps() -
427{ -
428 return pm_cache()->allPixmaps();
never executed: return pm_cache()->allPixmaps();
0
429} -
430 -
431 -
432 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial