Skip to content

Commit

Permalink
Remove some QHash and QLists.
Browse files Browse the repository at this point in the history
Change-Id: I153fa1abbe27f0724e453c5c979f740e956819c9
Reviewed-on: http://codereview.qt.nokia.com/3747
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Aug 30, 2011
1 parent fcb55f3 commit 275149f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 48 deletions.
38 changes: 16 additions & 22 deletions src/declarative/qml/qdeclarativecompiler.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
40 changes: 20 additions & 20 deletions src/declarative/qml/qdeclarativecompiler_p.h
Expand Up @@ -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;
Expand All @@ -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;
};
};
Expand Down
5 changes: 5 additions & 0 deletions src/declarative/qml/qdeclarativeintegercache.cpp
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/declarative/qml/qdeclarativeintegercache_p.h
Expand Up @@ -68,6 +68,7 @@ class QDeclarativeIntegerCache : public QDeclarativeRefCount

inline int count() const;
void add(const QString &, int);
void reserve(int);

int value(const QString &);
inline int value(const QHashedV8String &);
Expand Down
4 changes: 2 additions & 2 deletions src/declarative/qml/qdeclarativeparser.cpp
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/declarative/qml/qdeclarativeparser_p.h
Expand Up @@ -207,6 +207,7 @@ namespace QDeclarativeParser

// Used by compiler
QDeclarativeCompilerTypes::BindingReference *bindingReference;
int signalExpressionContextStack;

// Used in Property::ValueList lists
Value *nextValue;
Expand Down Expand Up @@ -396,6 +397,11 @@ namespace QDeclarativeParser

// Used by compiler
QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;

// Used by ComponentCompileState::AliasingObjectsList
Object *nextAliasingObject;
// Used by ComponentComppileState::IdList
Object *nextIdObject;
};

}
Expand Down
7 changes: 4 additions & 3 deletions src/declarative/qml/v4/qdeclarativev4compiler_p.h
Expand Up @@ -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

Expand All @@ -77,7 +78,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeV4Compiler
QDeclarativeParser::Object *context;
QDeclarativeParser::Property *property;
QDeclarativeParser::Variant expression;
QHash<QString, QDeclarativeParser::Object *> ids;
QDeclarativeCompilerTypes::IdList *ids;
QDeclarativeTypeNameCache *importCache;
QDeclarativeImports imports;
};
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 275149f

Please sign in to comment.