summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/codecs/qtextcodec.cpp52
-rw-r--r--src/corelib/plugin/qsystemlibrary.cpp5
-rw-r--r--src/corelib/plugin/qsystemlibrary_p.h4
3 files changed, 37 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;
}
diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp
index 568b398..2386cd6 100644
--- a/src/corelib/plugin/qsystemlibrary.cpp
+++ b/src/corelib/plugin/qsystemlibrary.cpp
@@ -77,6 +77,9 @@
in the documentation for LoadLibrary for Windows CE at MSDN.
(http://msdn.microsoft.com/en-us/library/ms886736.aspx)
*/
+
+QT_BEGIN_NAMESPACE
+
#if defined(Q_OS_WINCE)
HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
{
@@ -134,3 +137,5 @@ HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirect
}
#endif //Q_OS_WINCE
+
+QT_END_NAMESPACE
diff --git a/src/corelib/plugin/qsystemlibrary_p.h b/src/corelib/plugin/qsystemlibrary_p.h
index 3251a3c..8000a61 100644
--- a/src/corelib/plugin/qsystemlibrary_p.h
+++ b/src/corelib/plugin/qsystemlibrary_p.h
@@ -47,6 +47,8 @@
#include <qt_windows.h>
#include <QtCore/qstring.h>
+QT_BEGIN_NAMESPACE
+
class QSystemLibrary
{
public:
@@ -101,6 +103,8 @@ private:
bool m_didLoad;
};
+QT_END_NAMESPACE
+
#endif //Q_OS_WIN
#endif //QSYSTEMLIBRARY_P_H