Remove some QHash and QLists.
authorAaron Kennedy <aaron.kennedy@nokia.com>
Thu, 14 Jul 2011 07:34:06 +0000 (17:34 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 30 Aug 2011 11:18:28 +0000 (13:18 +0200)
Change-Id: I153fa1abbe27f0724e453c5c979f740e956819c9
Reviewed-on: http://codereview.qt.nokia.com/3747
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>

src/declarative/qml/qdeclarativecompiler.cpp
src/declarative/qml/qdeclarativecompiler_p.h
src/declarative/qml/qdeclarativeintegercache.cpp
src/declarative/qml/qdeclarativeintegercache_p.h
src/declarative/qml/qdeclarativeparser.cpp
src/declarative/qml/qdeclarativeparser_p.h
src/declarative/qml/v4/qdeclarativev4compiler_p.h
src/declarative/qml/v4/qdeclarativev4irbuilder.cpp

index 543ecb2..a597d1b 100644 (file)
@@ -1101,14 +1101,12 @@ void QDeclarativeCompiler::genObjectBody(QDeclarativeParser::Object *obj)
 
         } else if (v->type == Value::SignalExpression) {
 
-            BindingContext ctxt = compileState->signalExpressions.value(v);
-
             QDeclarativeInstruction store;
             store.setType(QDeclarativeInstruction::StoreSignal);
             store.storeSignal.signalIndex = prop->index;
             store.storeSignal.value =
                 output->indexForString(v->value.asScript().trimmed());
-            store.storeSignal.context = ctxt.stack;
+            store.storeSignal.context = v->signalExpressionContextStack;
             store.storeSignal.name = output->indexForByteArray(prop->name().toUtf8());
             store.storeSignal.line = v->location.start.line;
             output->addInstruction(store);
@@ -1292,7 +1290,7 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj,
 
         QString idVal = idProp->values.first()->primitive();
 
-        if (compileState->ids.contains(idVal))
+        if (compileState->ids.value(idVal))
             COMPILE_EXCEPTION(idProp, tr("id is not unique"));
 
         obj->id = idVal;
@@ -1452,7 +1450,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
             if (script.isEmpty())
                 COMPILE_EXCEPTION(prop, tr("Empty signal assignment"));
 
-            compileState->signalExpressions.insert(prop->values.first(), ctxt);
+            prop->values.first()->signalExpressionContextStack = ctxt.stack;
         }
     }
 
@@ -1811,7 +1809,7 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop,
 
     COMPILE_CHECK(checkValidId(idValue, val));
 
-    if (compileState->ids.contains(val))
+    if (compileState->ids.value(val))
         COMPILE_EXCEPTION(prop, tr("id is not unique"));
 
     prop->values.first()->type = Value::Id;
@@ -1824,10 +1822,10 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop,
 
 void QDeclarativeCompiler::addId(const QString &id, QDeclarativeParser::Object *obj)
 {
-    Q_ASSERT(!compileState->ids.contains(id));
+    Q_ASSERT(!compileState->ids.value(id));
     Q_ASSERT(obj->id == id);
     obj->idIndex = compileState->ids.count();
-    compileState->ids.insert(id, obj);
+    compileState->ids.append(obj);
 }
 
 void QDeclarativeCompiler::addBindingReference(BindingReference *ref)
@@ -2665,8 +2663,8 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
     obj->metadata = builder.toRelocatableData();
     builder.fromRelocatableData(&obj->extObject, obj->metatype, obj->metadata);
 
-    if (mode == IgnoreAliases && hasAlias)
-        compileState->aliasingObjects << obj;
+    if (mode == IgnoreAliases && hasAlias) 
+        compileState->aliasingObjects.append(obj);
 
     obj->synthdata = dynamicData;
 
@@ -2753,11 +2751,10 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder,
     if (alias.count() < 1 || alias.count() > 3)
         COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>"));
 
-    if (!compileState->ids.contains(alias.at(0)))
+    QDeclarativeParser::Object *idObject = compileState->ids.value(alias.at(0));
+    if (!idObject)
         COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0)));
 
-    QDeclarativeParser::Object *idObject = compileState->ids[alias.at(0)];
-
     QByteArray typeName;
 
     int propIdx = -1;
@@ -2917,11 +2914,9 @@ int QDeclarativeCompiler::genContextCache()
         return -1;
 
     QDeclarativeIntegerCache *cache = new QDeclarativeIntegerCache();
-
-    for (QHash<QString, QDeclarativeParser::Object *>::ConstIterator iter = compileState->ids.begin();
-         iter != compileState->ids.end();
-         ++iter) 
-        cache->add(iter.key(), (*iter)->idIndex);
+    cache->reserve(compileState->ids.count());
+    for (Object *o = compileState->ids.first(); o; o = compileState->ids.next(o)) 
+        cache->add(o->id, o->idIndex);
 
     output->contextCaches.append(cache);
     return output->contextCaches.count() - 1;
@@ -2951,14 +2946,13 @@ bool QDeclarativeCompiler::completeComponentBuild()
     if (componentStats)
         componentStats->componentStat.ids = compileState->ids.count();
 
-    for (int ii = 0; ii < compileState->aliasingObjects.count(); ++ii) {
-        QDeclarativeParser::Object *aliasObject = compileState->aliasingObjects.at(ii);
+    for (Object *aliasObject = compileState->aliasingObjects.first(); aliasObject; 
+         aliasObject = compileState->aliasingObjects.next(aliasObject)) 
         COMPILE_CHECK(buildDynamicMeta(aliasObject, ResolveAliases));
-    }
 
     QDeclarativeV4Compiler::Expression expr;
     expr.component = compileState->root;
-    expr.ids = compileState->ids;
+    expr.ids = &compileState->ids;
     expr.importCache = output->importCache;
     expr.imports = unit->imports();
 
index 7014ce2..0d800ba 100644 (file)
@@ -176,14 +176,27 @@ namespace QDeclarativeCompilerTypes {
         BindingReference *nextReference;
     };
 
+    struct IdList : public QFieldList<QDeclarativeParser::Object, 
+                                      &QDeclarativeParser::Object::nextIdObject>
+    {
+        QDeclarativeParser::Object *value(const QString &id) const {
+            for (QDeclarativeParser::Object *o = first(); o; o = next(o)) {
+                if (o->id == id)
+                    return o;
+            }
+            return 0;
+        }
+    };
+
     // Contains all the incremental compiler state about a component.  As
     // a single QML file can have multiple components defined, there may be
     // more than one of these for each compile
     struct ComponentCompileState : public QDeclarativePool::Class
     {
         ComponentCompileState() 
-            : parserStatusCount(0), pushedProperties(0), nested(false), v8BindingProgramLine(-1), root(0) {}
-        QHash<QString, QDeclarativeParser::Object *> ids;
+        : parserStatusCount(0), pushedProperties(0), nested(false), v8BindingProgramLine(-1), root(0) {}
+
+        IdList ids;
         int parserStatusCount;
         int pushedProperties;
         bool nested;
@@ -193,25 +206,12 @@ namespace QDeclarativeCompilerTypes {
         int v8BindingProgramLine;
         int v8BindingProgramIndex;
 
-        struct BindingReferenceList {
-            BindingReferenceList() : _count(0), _first(0) {}
-            QDeclarativeCompilerTypes::BindingReference *first() const { return _first; }
-            void prepend(QDeclarativeCompilerTypes::BindingReference *ref) {
-                Q_ASSERT(ref);
-                Q_ASSERT(0 == ref->nextReference);
-                ref->nextReference = _first;
-                _first = ref;
-                ++_count;
-            }
-            int count() const { return _count; }
-        private:
-            int _count;
-            QDeclarativeCompilerTypes::BindingReference *_first;
-        };
-
+        typedef QDeclarativeCompilerTypes::BindingReference B;
+        typedef QFieldList<B, &B::nextReference> BindingReferenceList;
         BindingReferenceList bindings;
-        QHash<QDeclarativeParser::Value *, QDeclarativeCompilerTypes::BindingContext> signalExpressions;
-        QList<QDeclarativeParser::Object *> aliasingObjects;
+        typedef QDeclarativeParser::Object O;
+        typedef QFieldList<O, &O::nextAliasingObject> AliasingObjectsList;
+        AliasingObjectsList aliasingObjects;
         QDeclarativeParser::Object *root;
     };
 };
index ef99c63..16bf8d1 100644 (file)
@@ -61,6 +61,11 @@ QString QDeclarativeIntegerCache::findId(int value) const
     return QString();
 }
 
+void QDeclarativeIntegerCache::reserve(int size)
+{ 
+    stringCache.reserve(size);
+}
+
 void QDeclarativeIntegerCache::add(const QString &id, int value)
 {
     Q_ASSERT(!stringCache.contains(id));
index a66457c..1ac03ad 100644 (file)
@@ -68,6 +68,7 @@ public:
 
     inline int count() const;
     void add(const QString &, int);
+    void reserve(int);
 
     int value(const QString &);
     inline int value(const QHashedV8String &);
index bba2621..eca0858 100644 (file)
@@ -67,7 +67,7 @@ using namespace QDeclarativeParser;
 
 QDeclarativeParser::Object::Object()
 : type(-1), idIndex(-1), metatype(0), synthCache(0), defaultProperty(0), parserStatusCast(-1),
-  componentCompileState(0)
+  componentCompileState(0), nextAliasingObject(0), nextIdObject(0)
 {
 }
 
@@ -233,7 +233,7 @@ bool QDeclarativeParser::Property::isEmpty() const
 }
 
 QDeclarativeParser::Value::Value()
-: type(Unknown), object(0), bindingReference(0), nextValue(0)
+: type(Unknown), object(0), bindingReference(0), signalExpressionContextStack(0), nextValue(0)
 {
 }
 
index 496041b..f7b71c4 100644 (file)
@@ -207,6 +207,7 @@ namespace QDeclarativeParser
 
         // Used by compiler
         QDeclarativeCompilerTypes::BindingReference *bindingReference;
+        int signalExpressionContextStack;
 
         // Used in Property::ValueList lists
         Value *nextValue;
@@ -396,6 +397,11 @@ namespace QDeclarativeParser
 
         // Used by compiler
         QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
+
+        // Used by ComponentCompileState::AliasingObjectsList
+        Object *nextAliasingObject;
+        // Used by ComponentComppileState::IdList
+        Object *nextIdObject;
     };
 
 }
index cc93f4d..bf53fef 100644 (file)
@@ -53,8 +53,9 @@
 // We mean it.
 //
 
-#include "private/qdeclarativeexpression_p.h"
-#include "private/qdeclarativebinding_p.h"
+#include <private/qdeclarativeexpression_p.h>
+#include <private/qdeclarativebinding_p.h>
+#include <private/qdeclarativecompiler_p.h>
 
 QT_BEGIN_HEADER
 
@@ -77,7 +78,7 @@ public:
         QDeclarativeParser::Object *context;
         QDeclarativeParser::Property *property;
         QDeclarativeParser::Variant expression;
-        QHash<QString, QDeclarativeParser::Object *> ids;
+        QDeclarativeCompilerTypes::IdList *ids;
         QDeclarativeTypeNameCache *importCache;
         QDeclarativeImports imports;
     };
index 6a6f4f0..fbee5a6 100644 (file)
@@ -439,7 +439,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::IdentifierExpression *ast)
     } else if (m_engine->v8engine()->illegalNames().contains(name) ) {
         if (qmlVerboseCompiler()) qWarning() << "*** illegal symbol:" << name;
         return false;
-    } else if (const QDeclarativeParser::Object *obj = m_expression->ids.value(name)) {
+    } else if (const QDeclarativeParser::Object *obj = m_expression->ids->value(name)) {
         IR::Name *code = _block->ID_OBJECT(name, obj, line, column);
         if (obj == m_expression->component)
             code->storage = IR::Name::RootStorage;