QTextCodec: micro-optimize loops.
Don't use index-based iteration, but use iterators. Change-Id: If8dabd56ff880191bb53861e31bfa6a007802c9c Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1c0f247671
commit
1d38ecf542
@ -47,6 +47,9 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef QList<QTextCodec*>::ConstIterator TextCodecListConstIt;
|
||||
typedef QList<QByteArray>::ConstIterator ByteArrayListConstIt;
|
||||
|
||||
static void qIcuCodecStateFree(QTextCodec::ConverterState *state)
|
||||
{
|
||||
ucnv_close(static_cast<UConverter *>(state->d));
|
||||
@ -487,20 +490,21 @@ QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name)
|
||||
return codec;
|
||||
}
|
||||
|
||||
for (int i = 0; i < globalData->allCodecs.size(); ++i) {
|
||||
QTextCodec *cursor = globalData->allCodecs.at(i);
|
||||
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
|
||||
QTextCodec *cursor = *it;
|
||||
if (qTextCodecNameMatch(cursor->name(), standardName)) {
|
||||
if (cache)
|
||||
cache->insert(standardName, cursor);
|
||||
return cursor;
|
||||
}
|
||||
QList<QByteArray> aliases = cursor->aliases();
|
||||
for (int y = 0; y < aliases.size(); ++y)
|
||||
if (qTextCodecNameMatch(aliases.at(y), standardName)) {
|
||||
for (ByteArrayListConstIt ait = aliases.constBegin(), acend = aliases.constEnd(); ait != acend; ++ait) {
|
||||
if (qTextCodecNameMatch(*ait, standardName)) {
|
||||
if (cache)
|
||||
cache->insert(standardName, cursor);
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QTextCodec *c = loadQtCodec(standardName);
|
||||
|
@ -87,6 +87,9 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef QList<QTextCodec*>::ConstIterator TextCodecListConstIt;
|
||||
typedef QList<QByteArray>::ConstIterator ByteArrayListConstIt;
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive));
|
||||
QMutex *qTextCodecsMutex() { return textCodecsMutex(); }
|
||||
|
||||
@ -519,20 +522,21 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
|
||||
return codec;
|
||||
}
|
||||
|
||||
for (int i = 0; i < globalData->allCodecs.size(); ++i) {
|
||||
QTextCodec *cursor = globalData->allCodecs.at(i);
|
||||
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
|
||||
QTextCodec *cursor = *it;
|
||||
if (qTextCodecNameMatch(cursor->name(), name)) {
|
||||
if (cache)
|
||||
cache->insert(name, cursor);
|
||||
return cursor;
|
||||
}
|
||||
QList<QByteArray> aliases = cursor->aliases();
|
||||
for (int y = 0; y < aliases.size(); ++y)
|
||||
if (qTextCodecNameMatch(aliases.at(y), name)) {
|
||||
for (ByteArrayListConstIt ait = aliases.constBegin(), acend = aliases.constEnd(); ait != acend; ++ait) {
|
||||
if (qTextCodecNameMatch(*ait, name)) {
|
||||
if (cache)
|
||||
cache->insert(name, cursor);
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -567,9 +571,8 @@ QTextCodec* QTextCodec::codecForMib(int mib)
|
||||
return codec;
|
||||
}
|
||||
|
||||
QList<QTextCodec*>::ConstIterator i;
|
||||
for (int i = 0; i < globalData->allCodecs.size(); ++i) {
|
||||
QTextCodec *cursor = globalData->allCodecs.at(i);
|
||||
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
|
||||
QTextCodec *cursor = *it;
|
||||
if (cursor->mibEnum() == mib) {
|
||||
if (cache)
|
||||
cache->insert(key, cursor);
|
||||
@ -604,9 +607,9 @@ QList<QByteArray> QTextCodec::availableCodecs()
|
||||
|
||||
QList<QByteArray> codecs;
|
||||
|
||||
for (int i = 0; i < globalData->allCodecs.size(); ++i) {
|
||||
codecs += globalData->allCodecs.at(i)->name();
|
||||
codecs += globalData->allCodecs.at(i)->aliases();
|
||||
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it) {
|
||||
codecs += (*it)->name();
|
||||
codecs += (*it)->aliases();
|
||||
}
|
||||
|
||||
#ifdef QT_USE_ICU
|
||||
@ -636,8 +639,8 @@ QList<int> QTextCodec::availableMibs()
|
||||
|
||||
QList<int> codecs;
|
||||
|
||||
for (int i = 0; i < globalData->allCodecs.size(); ++i)
|
||||
codecs += globalData->allCodecs.at(i)->mibEnum();
|
||||
for (TextCodecListConstIt it = globalData->allCodecs.constBegin(), cend = globalData->allCodecs.constEnd(); it != cend; ++it)
|
||||
codecs += (*it)->mibEnum();
|
||||
|
||||
return codecs;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user