summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-17 15:36:59 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-02-17 15:36:59 (GMT)
commit54b20c491f7e182f6b98f65b7e9e8e68286d6109 (patch)
tree7f17d6b2540ea226eb7d8d1b830f31f1a032316a /src/corelib/codecs
parentdcb2678f39345b66c5303e74c156654a8d13fe83 (diff)
parent17a0a50a101fc9863d0dffd0dcb887ba68a99622 (diff)
downloadQt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.zip
Qt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.tar.gz
Qt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.tar.bz2
Merge branch '4.6' into qt-master-from-4.6
Conflicts: mkspecs/common/symbian/symbian.conf src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp tools/assistant/tools/assistant/helpviewer.cpp
Diffstat (limited to 'src/corelib/codecs')
-rw-r--r--src/corelib/codecs/qtextcodec.cpp52
-rw-r--r--src/corelib/codecs/qtextcodec.h2
2 files changed, 45 insertions, 9 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index 1c607a6..ca5e658 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -80,6 +80,7 @@
#endif // QT_NO_CODECS
#include "qlocale.h"
#include "qmutex.h"
+#include "qhash.h"
#include <stdlib.h>
#include <ctype.h>
@@ -172,6 +173,7 @@ 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
@@ -935,6 +937,7 @@ QTextCodec::~QTextCodec()
QMutexLocker locker(textCodecsMutex());
#endif
all->removeAll(this);
+ clearCaches = 0x1 | 0x2;
}
}
@@ -961,17 +964,33 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
#endif
setup();
+ static QHash <QByteArray, QTextCodec *> cache;
+ if (clearCaches & 0x1) {
+ cache.clear();
+ clearCaches &= ~0x1;
+ }
+ 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))
+ if (nameMatch(cursor->name(), name)) {
+ 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))
+ if (nameMatch(aliases.at(y), name)) {
+ cache.insert(name, cursor);
return cursor;
+ }
}
- return createForName(name);
+ codec = createForName(name);
+ if (codec)
+ cache.insert(name, codec);
+ return codec;
}
@@ -986,19 +1005,34 @@ QTextCodec* QTextCodec::codecForMib(int mib)
#endif
setup();
- // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map
- // this correctly for compatibility.
- if (mib == 1000)
- mib = 1015;
+ static QHash <int, QTextCodec *> cache;
+ if (clearCaches & 0x2) {
+ cache.clear();
+ clearCaches &= ~0x2;
+ }
+ QTextCodec *codec = cache.value(mib);
+ if (codec)
+ return codec;
QList<QTextCodec*>::ConstIterator i;
for (int i = 0; i < all->size(); ++i) {
QTextCodec *cursor = all->at(i);
- if (cursor->mibEnum() == mib)
+ if (cursor->mibEnum() == mib) {
+ cache.insert(mib, cursor);
return cursor;
+ }
}
- return createForMib(mib);
+ codec = createForMib(mib);
+
+ // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map
+ // this correctly for compatibility.
+ if (!codec && mib == 1000)
+ return codecForMib(1015);
+
+ if (codec)
+ cache.insert(mib, codec);
+ return codec;
}
/*!
diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h
index 5012b42..e00d7b4 100644
--- a/src/corelib/codecs/qtextcodec.h
+++ b/src/corelib/codecs/qtextcodec.h
@@ -174,8 +174,10 @@ private:
friend class QXmlStreamWriter;
friend class QXmlStreamWriterPrivate;
+#if defined Q_XMLSTREAM_RENAME_SYMBOLS
friend class QCoreXmlStreamWriter;
friend class QCoreXmlStreamWriterPrivate;
+#endif
};
class Q_CORE_EXPORT QTextDecoder {