summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
authorA-Team <ateam@pad.test.qt.nokia.com>2010-10-05 00:00:19 +0200
committerA-Team <ateam@pad.test.qt.nokia.com>2010-10-05 00:00:19 +0200
commite3bcf44684aa30271c986911b328c9d9c372912a (patch)
treede7f835e6fe69b610e64397a768f1630fb8b5c54 /src/corelib/codecs
parentf3817bc1a7bc3df360af9116dfd96f3181816472 (diff)
parenta7bf1cfb1a75c35e837c01f4a5b0697fc8961148 (diff)
Merge branch '4.7-upstream' into 4.7-doc
Diffstat (limited to 'src/corelib/codecs')
-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 c9fbec870b..83e1f0cfef 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;
}