diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2013-04-12 15:23:22 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-12 19:50:53 +0200 |
commit | 4f400eeec1eed2d41f351ffd3f160cbde133c5eb (patch) | |
tree | 3ae3265aa5bde13aef1be16f1e943a0dd62680fd /src | |
parent | be08ef61313eb84d608eb56264189fc85e171eff (diff) |
QFontCache: Make clear() really clear/free cached data it maintains
QFontCache::clear() now frees everything it keeps and resets the cache costs.
Change-Id: I23ac2cab5c7c7d70db03f048b6fde151a18f92e1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: jian liang <jianliang79@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qfont.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 1d6cf3ceca..9d603bb08d 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2639,18 +2639,6 @@ QFontCache::QFontCache() QFontCache::~QFontCache() { clear(); - { - EngineDataCache::ConstIterator it = engineDataCache.constBegin(), - end = engineDataCache.constEnd(); - while (it != end) { - if (!it.value()->ref.deref()) - delete it.value(); - else - FC_DEBUG("QFontCache::~QFontCache: engineData %p still has refcount %d", - it.value(), it.value()->ref.load()); - ++it; - } - } } void QFontCache::clear() @@ -2669,29 +2657,47 @@ void QFontCache::clear() data->engines[i] = 0; } } + if (!data->ref.deref()) { + delete data; + } else { + FC_DEBUG("QFontCache::clear: engineData %p still has refcount %d", + data, data->ref.load()); + } ++it; } } - bool mightHaveEnginesLeftForCleanup = true; - while (mightHaveEnginesLeftForCleanup) { + engineDataCache.clear(); + + + bool mightHaveEnginesLeftForCleanup; + do { mightHaveEnginesLeftForCleanup = false; for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); - it != end; ++it) { - if (it.value().data && engineCacheCount.value(it.value().data) > 0) { - --engineCacheCount[it.value().data]; - if (!it.value().data->ref.deref()) { - Q_ASSERT(engineCacheCount.value(it.value().data) == 0); - delete it.value().data; - mightHaveEnginesLeftForCleanup = true; + it != end; ++it) { + QFontEngine *engine = it.value().data; + if (engine) { + const int cacheCount = --engineCacheCount[engine]; + Q_ASSERT(cacheCount >= 0); + if (!engine->ref.deref()) { + Q_ASSERT(cacheCount == 0); + mightHaveEnginesLeftForCleanup = engine->type() == QFontEngine::Multi; + delete engine; + } else if (cacheCount == 0) { + FC_DEBUG("QFontCache::clear: engine %p still has refcount %d", + engine, engine->ref.load()); } it.value().data = 0; } } - } + } while (mightHaveEnginesLeftForCleanup); engineCache.clear(); engineCacheCount.clear(); + + + total_cost = 0; + max_cost = min_cost; } |