summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-02-17 21:55:18 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-02-17 21:55:18 (GMT)
commit9eacc56619ce471a9777f88c89f64ca95cd6ae63 (patch)
treeb52b46a26a04889145a30339da28e5aa99756b1c /src/corelib/codecs
parentfd3f9dd0f31efeea3aa0ec28b54c70d85712c7ba (diff)
parent54b20c491f7e182f6b98f65b7e9e8e68286d6109 (diff)
downloadQt-9eacc56619ce471a9777f88c89f64ca95cd6ae63.zip
Qt-9eacc56619ce471a9777f88c89f64ca95cd6ae63.tar.gz
Qt-9eacc56619ce471a9777f88c89f64ca95cd6ae63.tar.bz2
Merge branch 'qt-master-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration into master-integration
* 'qt-master-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration: (249 commits) Fixed autotest failure in tst_QGraphicsScene::render on Maemo. Changed function names in audio input example to clarify meaning Tidied up debug output in audio input example Removed redundant strings from audio input example Cleaned up memory management in audio input example Changed variable names in audio input example to match Qt code style Made level calculation in audio input example work for all formats Removed unused variable from audio input example Update suspend/resume button label in audio input example Changed function names in audio output example to clarify meaning Cleaned up implementation of audio output example Tidied up debug output in audio output example Removed redundant strings from audio output example Cleaned up memory management in audio output example Changed variable names in audio output example to match Qt code style Made data generation in audio output example work for all formats Update suspend/resume button label in audio output example Added missing override in audio output example QLocalSocket::isValid on Windows must check for broken connection Fix an issue with the error signal in a callWithCallback not being ...
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 {