aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-02-23 13:44:12 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-02-26 15:13:34 +0000
commit5163c11952a39458dd6d7ba10391c2b39ccdf86a (patch)
tree98c03a10d5c9e51a5aa6f950d642ee6a7b93031f /src
parenta7c0e62b9122a8d210149570be8834401b9b36d3 (diff)
QtQml: Micro-optimize iterator loops.
Avoid repeated instantiation of end() in loops, use variable instead. Change-Id: I3bb1c6918cfd16a5dcefbcc03c442e99fe9bf76b Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4codegen.cpp4
-rw-r--r--src/qml/debugger/qqmldebugserver.cpp8
-rw-r--r--src/qml/jsapi/qjsengine.cpp4
-rw-r--r--src/qml/jsruntime/qv4engine.cpp5
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp2
-rw-r--r--src/qml/qml/qqmlengine.cpp7
-rw-r--r--src/qml/qml/qqmlmetatype.cpp6
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp4
-rw-r--r--src/qml/qml/qqmltypeloader.cpp8
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp8
-rw-r--r--src/qml/util/qqmladaptormodel.cpp2
11 files changed, 31 insertions, 27 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index c89a49c1ca..27aecdd3ed 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -1965,7 +1965,7 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast,
// variables in global code are properties of the global context object, not locals as with other functions.
if (_env->compilationMode == FunctionCode || _env->compilationMode == QmlBinding) {
unsigned t = 0;
- for (Environment::MemberMap::iterator it = _env->members.begin(); it != _env->members.end(); ++it) {
+ for (Environment::MemberMap::iterator it = _env->members.begin(), end = _env->members.end(); it != end; ++it) {
const QString &local = it.key();
function->LOCAL(local);
(*it).index = t;
@@ -1984,7 +1984,7 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast,
}
IR::ExprList *args = 0;
- for (Environment::MemberMap::const_iterator it = _env->members.constBegin(); it != _env->members.constEnd(); ++it) {
+ for (Environment::MemberMap::const_iterator it = _env->members.constBegin(), cend = _env->members.constEnd(); it != cend; ++it) {
const QString &local = it.key();
IR::ExprList *next = function->New<IR::ExprList>();
next->expr = entryBlock->NAME(local, 0, 0);
diff --git a/src/qml/debugger/qqmldebugserver.cpp b/src/qml/debugger/qqmldebugserver.cpp
index c9e30e06b6..b0302181ee 100644
--- a/src/qml/debugger/qqmldebugserver.cpp
+++ b/src/qml/debugger/qqmldebugserver.cpp
@@ -471,6 +471,8 @@ QQmlDebugServer::QQmlDebugServer()
void QQmlDebugServer::receiveMessage(const QByteArray &message)
{
+ typedef QHash<QString, QQmlDebugService*>::const_iterator DebugServiceConstIt;
+
// to be executed in debugger thread
Q_ASSERT(QThread::currentThread() == thread());
@@ -516,8 +518,7 @@ void QQmlDebugServer::receiveMessage(const QByteArray &message)
QMutexLocker helloLock(&d->helloMutex);
d->gotHello = true;
- QHash<QString, QQmlDebugService*>::ConstIterator iter = d->plugins.constBegin();
- for (; iter != d->plugins.constEnd(); ++iter) {
+ for (DebugServiceConstIt iter = d->plugins.constBegin(), cend = d->plugins.constEnd(); iter != cend; ++iter) {
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
if (d->clientPlugins.contains(iter.key()))
newState = QQmlDebugService::Enabled;
@@ -534,8 +535,7 @@ void QQmlDebugServer::receiveMessage(const QByteArray &message)
QStringList oldClientPlugins = d->clientPlugins;
in >> d->clientPlugins;
- QHash<QString, QQmlDebugService*>::ConstIterator iter = d->plugins.constBegin();
- for (; iter != d->plugins.constEnd(); ++iter) {
+ for (DebugServiceConstIt iter = d->plugins.constBegin(), cend = d->plugins.constEnd(); iter != cend; ++iter) {
const QString pluginName = iter.key();
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
if (d->clientPlugins.contains(pluginName))
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index eb97d5fc6b..896331593f 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -562,7 +562,9 @@ QJSEnginePrivate *QJSEnginePrivate::get(QV4::ExecutionEngine *e)
QJSEnginePrivate::~QJSEnginePrivate()
{
- for (QHash<const QMetaObject *, QQmlPropertyCache *>::Iterator iter = propertyCache.begin(); iter != propertyCache.end(); ++iter)
+ typedef QHash<const QMetaObject *, QQmlPropertyCache *>::Iterator PropertyCacheIt;
+
+ for (PropertyCacheIt iter = propertyCache.begin(), end = propertyCache.end(); iter != end; ++iter)
(*iter)->release();
}
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 1275e2a1d0..2c8a68812a 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -1335,7 +1335,7 @@ static QV4::ReturnedValue objectFromVariantMap(QV4::ExecutionEngine *e, const QV
QV4::ScopedObject o(scope, e->newObject());
QV4::ScopedString s(scope);
QV4::ScopedValue v(scope);
- for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter) {
+ for (QVariantMap::const_iterator iter = map.begin(), cend = map.end(); iter != cend; ++iter) {
s = e->newString(iter.key());
uint idx = s->asArrayIndex();
if (idx > 16 && (!o->arrayData() || idx > o->arrayData()->length() * 2))
@@ -1501,10 +1501,9 @@ static QV4::ReturnedValue variantMapToJS(QV4::ExecutionEngine *v4, const QVarian
{
QV4::Scope scope(v4);
QV4::ScopedObject o(scope, v4->newObject());
- QVariantMap::const_iterator it;
QV4::ScopedString s(scope);
QV4::ScopedValue v(scope);
- for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) {
+ for (QVariantMap::const_iterator it = vmap.constBegin(), cend = vmap.constEnd(); it != cend; ++it) {
s = v4->newIdentifier(it.key());
v = variantToJS(v4, it.value());
uint idx = s->asArrayIndex();
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index 911fc7337c..e7905974df 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -1002,7 +1002,7 @@ QV4::ReturnedValue JsonObject::fromJsonObject(ExecutionEngine *engine, const QJs
ScopedObject o(scope, engine->newObject());
ScopedString s(scope);
ScopedValue v(scope);
- for (QJsonObject::const_iterator it = object.begin(); it != object.end(); ++it) {
+ for (QJsonObject::const_iterator it = object.begin(), cend = object.end(); it != cend; ++it) {
v = fromJsonValue(engine, it.value());
o->put((s = engine->newString(it.key())), v);
}
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 916f848bbe..70090bd3f9 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -595,6 +595,9 @@ QQmlEnginePrivate::QQmlEnginePrivate(QQmlEngine *e)
QQmlEnginePrivate::~QQmlEnginePrivate()
{
+ typedef QHash<QPair<QQmlType *, int>, QQmlPropertyCache *>::Iterator TypePropertyCacheIt;
+ typedef QHash<int, QQmlCompiledData *>::Iterator CompositeTypesIt;
+
if (inProgressCreations)
qWarning() << QQmlEngine::tr("There are still \"%1\" items in the process of being created at engine destruction.").arg(inProgressCreations);
@@ -612,9 +615,9 @@ QQmlEnginePrivate::~QQmlEnginePrivate()
if (incubationController) incubationController->d = 0;
incubationController = 0;
- for(QHash<QPair<QQmlType *, int>, QQmlPropertyCache *>::Iterator iter = typePropertyCache.begin(); iter != typePropertyCache.end(); ++iter)
+ for (TypePropertyCacheIt iter = typePropertyCache.begin(), end = typePropertyCache.end(); iter != end; ++iter)
(*iter)->release();
- for (QHash<int, QQmlCompiledData *>::Iterator iter = m_compositeTypes.begin(); iter != m_compositeTypes.end(); ++iter)
+ for (CompositeTypesIt iter = m_compositeTypes.begin(), end = m_compositeTypes.end(); iter != end; ++iter)
iter.value()->isRegisteredWithEngine = false;
delete profiler;
}
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 6dc18b4b05..9779773b05 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -143,8 +143,7 @@ QQmlMetaTypeData::~QQmlMetaTypeData()
for (int i = 0; i < types.count(); ++i)
delete types.at(i);
- TypeModules::const_iterator i = uriToModule.constBegin();
- for (; i != uriToModule.constEnd(); ++i)
+ for (TypeModules::const_iterator i = uriToModule.constBegin(), cend = uriToModule.constEnd(); i != cend; ++i)
delete *i;
}
@@ -1096,8 +1095,7 @@ void qmlClearTypeRegistrations() // Declared in qqml.h
for (int i = 0; i < data->types.count(); ++i)
delete data->types.at(i);
- QQmlMetaTypeData::TypeModules::const_iterator i = data->uriToModule.constBegin();
- for (; i != data->uriToModule.constEnd(); ++i)
+ for (QQmlMetaTypeData::TypeModules::const_iterator i = data->uriToModule.constBegin(), cend = data->uriToModule.constEnd(); i != cend; ++i)
delete *i;
data->types.clear();
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index bf38fc79a6..dd1f93ec00 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -1053,7 +1053,7 @@ void QQmlPropertyData::markAsOverrideOf(QQmlPropertyData *predecessor)
QStringList QQmlPropertyCache::propertyNames() const
{
QStringList keys;
- for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
+ for (StringCache::ConstIterator iter = stringCache.begin(), cend = stringCache.end(); iter != cend; ++iter)
keys.append(iter.key());
return keys;
}
@@ -1374,7 +1374,7 @@ void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder)
QList<QPair<QString, QQmlPropertyData *> > properties;
QList<QPair<QString, QQmlPropertyData *> > methods;
- for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
+ for (StringCache::ConstIterator iter = stringCache.begin(), cend = stringCache.end(); iter != cend; ++iter)
Insert::in(this, properties, methods, iter, iter.value().second);
Q_ASSERT(properties.count() == propertyIndexCache.count());
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index ea9b83cee3..0bf8043cdb 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -1884,11 +1884,11 @@ and qmldir information.
*/
void QQmlTypeLoader::clearCache()
{
- for (TypeCache::Iterator iter = m_typeCache.begin(); iter != m_typeCache.end(); ++iter)
+ for (TypeCache::Iterator iter = m_typeCache.begin(), end = m_typeCache.end(); iter != end; ++iter)
(*iter)->release();
- for (ScriptCache::Iterator iter = m_scriptCache.begin(); iter != m_scriptCache.end(); ++iter)
+ for (ScriptCache::Iterator iter = m_scriptCache.begin(), end = m_scriptCache.end(); iter != end; ++iter)
(*iter)->release();
- for (QmldirCache::Iterator iter = m_qmldirCache.begin(); iter != m_qmldirCache.end(); ++iter)
+ for (QmldirCache::Iterator iter = m_qmldirCache.begin(), end = m_qmldirCache.end(); iter != end; ++iter)
(*iter)->release();
qDeleteAll(m_importDirCache);
qDeleteAll(m_importQmlDirCache);
@@ -1904,7 +1904,7 @@ void QQmlTypeLoader::trimCache()
{
while (true) {
QList<TypeCache::Iterator> unneededTypes;
- for (TypeCache::Iterator iter = m_typeCache.begin(); iter != m_typeCache.end(); ++iter) {
+ for (TypeCache::Iterator iter = m_typeCache.begin(), end = m_typeCache.end(); iter != end; ++iter) {
QQmlTypeData *typeData = iter.value();
if (typeData->m_compiledData && typeData->m_compiledData->count() == 1) {
// There are no live objects of this type
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index b38190336e..201fd4572c 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -2275,21 +2275,23 @@ void QQmlDelegateModelGroupPrivate::emitModelUpdated(bool reset)
changeSet.clear();
}
+typedef QQmlDelegateModelGroupEmitterList::iterator GroupEmitterListIt;
+
void QQmlDelegateModelGroupPrivate::createdPackage(int index, QQuickPackage *package)
{
- for (QQmlDelegateModelGroupEmitterList::iterator it = emitters.begin(); it != emitters.end(); ++it)
+ for (GroupEmitterListIt it = emitters.begin(), end = emitters.end(); it != end; ++it)
it->createdPackage(index, package);
}
void QQmlDelegateModelGroupPrivate::initPackage(int index, QQuickPackage *package)
{
- for (QQmlDelegateModelGroupEmitterList::iterator it = emitters.begin(); it != emitters.end(); ++it)
+ for (GroupEmitterListIt it = emitters.begin(), end = emitters.end(); it != end; ++it)
it->initPackage(index, package);
}
void QQmlDelegateModelGroupPrivate::destroyingPackage(QQuickPackage *package)
{
- for (QQmlDelegateModelGroupEmitterList::iterator it = emitters.begin(); it != emitters.end(); ++it)
+ for (GroupEmitterListIt it = emitters.begin(), end = emitters.end(); it != end; ++it)
it->destroyingPackage(package);
}
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 2130cdeb1f..356970eef0 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -527,7 +527,7 @@ public:
const QByteArray propertyType = QByteArrayLiteral("QVariant");
const QHash<int, QByteArray> names = model.aim()->roleNames();
- for (QHash<int, QByteArray>::const_iterator it = names.begin(); it != names.end(); ++it) {
+ for (QHash<int, QByteArray>::const_iterator it = names.begin(), cend = names.end(); it != cend; ++it) {
const int propertyId = propertyRoles.count();
propertyRoles.append(it.key());
roleNames.insert(it.value(), it.key());