summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-09-29 12:08:21 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-09-29 12:28:33 (GMT)
commit02aecce59cb76ceb88f63520355381c3b5c5a513 (patch)
treeae497ef4c77d3f9ae03cee4bc7bd22bfca50f8ab /src/corelib
parent33f525e636ef8fa64a15d3e66c56adaea0075bda (diff)
downloadQt-02aecce59cb76ceb88f63520355381c3b5c5a513.zip
Qt-02aecce59cb76ceb88f63520355381c3b5c5a513.tar.gz
Qt-02aecce59cb76ceb88f63520355381c3b5c5a513.tar.bz2
QTextCodec: Fix valgrind warning when using QTextCodec in destructions functions
Reviewed-by: Denis
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/codecs/qtextcodec.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index c9fbec8..83e1f0c 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -110,6 +110,10 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QTextCodecFactoryInterface_iid, QLatin1String("/codecs")))
#endif
+//Cache for QTextCodec::codecForName and codecForMib.
+typedef QHash<QByteArray, QTextCodec *> QTextCodecCache;
+Q_GLOBAL_STATIC(QTextCodecCache, qTextCodecCache)
+
static char qtolower(register char c)
{ if (c >= 'A' && c <= 'Z') return c + 0x20; return c; }
@@ -181,7 +185,6 @@ static QTextCodec *createForMib(int mib)
}
static QList<QTextCodec*> *all = 0;
-static int clearCaches = 0; // flags specifying if caches should be invalided: 0x1 codecForName, 0x2 codecForMib
#ifdef Q_DEBUG_TEXTCODEC
static bool destroying_is_ok = false;
#endif
@@ -1007,7 +1010,9 @@ QTextCodec::~QTextCodec()
QMutexLocker locker(textCodecsMutex());
#endif
all->removeAll(this);
- clearCaches = 0x1 | 0x2;
+ QTextCodecCache *cache = qTextCodecCache();
+ if (cache)
+ cache->clear();
}
}
@@ -1037,32 +1042,33 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
if (!validCodecs())
return 0;
- static QHash <QByteArray, QTextCodec *> cache;
- if (clearCaches & 0x1) {
- cache.clear();
- clearCaches &= ~0x1;
+ QTextCodecCache *cache = qTextCodecCache();
+ QTextCodec *codec;
+ if (cache) {
+ codec = cache->value(name);
+ if (codec)
+ return codec;
}
- QTextCodec *codec = cache.value(name);
- if (codec)
- return codec;
for (int i = 0; i < all->size(); ++i) {
QTextCodec *cursor = all->at(i);
if (nameMatch(cursor->name(), name)) {
- cache.insert(name, cursor);
+ if (cache)
+ cache->insert(name, cursor);
return cursor;
}
QList<QByteArray> aliases = cursor->aliases();
for (int y = 0; y < aliases.size(); ++y)
if (nameMatch(aliases.at(y), name)) {
- cache.insert(name, cursor);
+ if (cache)
+ cache->insert(name, cursor);
return cursor;
}
}
codec = createForName(name);
- if (codec)
- cache.insert(name, codec);
+ if (codec && cache)
+ cache->insert(name, codec);
return codec;
}
@@ -1081,20 +1087,18 @@ QTextCodec* QTextCodec::codecForMib(int mib)
if (!validCodecs())
return 0;
- static QHash <int, QTextCodec *> cache;
- if (clearCaches & 0x2) {
- cache.clear();
- clearCaches &= ~0x2;
- }
- QTextCodec *codec = cache.value(mib);
- if (codec)
- return codec;
+ QByteArray key = "MIB: " + QByteArray::number(mib);
+ QTextCodecCache *cache = qTextCodecCache();
+ QTextCodec *codec;
+ if (cache)
+ codec = cache->value(key);
QList<QTextCodec*>::ConstIterator i;
for (int i = 0; i < all->size(); ++i) {
QTextCodec *cursor = all->at(i);
if (cursor->mibEnum() == mib) {
- cache.insert(mib, cursor);
+ if (cache)
+ cache->insert(key, cursor);
return cursor;
}
}
@@ -1106,8 +1110,8 @@ QTextCodec* QTextCodec::codecForMib(int mib)
if (!codec && mib == 1000)
return codecForMib(1015);
- if (codec)
- cache.insert(mib, codec);
+ if (codec && cache)
+ cache->insert(key, codec);
return codec;
}