diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-21 23:08:53 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-30 13:18:28 +0200 |
commit | 18307bfffff4cf8867706c9b1eafe163465379a7 (patch) | |
tree | 8bf0cdc7e746a12d34fde439af6c252878730570 /src/declarative/qml/qdeclarativeparser.cpp | |
parent | bd18281fed1ea614ed40ce947357cf799496fb79 (diff) |
Introduce QHashField for use in "contains" tests.
Change-Id: I35aadace15b71b44c1b9e30a76eadf79fe03afad
Reviewed-on: http://codereview.qt.nokia.com/3767
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativeparser.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeparser.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 00bad1d9e6..6a78598317 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -132,14 +132,18 @@ void QDeclarativeParser::Object::addScriptStringProperty(Property *p) scriptStringProperties.append(p); } +// This lookup is optimized for missing, and having to create a new property. Property *QDeclarativeParser::Object::getProperty(const QHashedStringRef &name, bool create) { - for (Property *p = properties.first(); p; p = properties.next(p)) { - if (p->name() == name) - return p; - } - if (create) { + quint32 h = name.hash(); + if (propertiesHashField.testAndSet(h)) { + for (Property *p = properties.first(); p; p = properties.next(p)) { + if (p->name() == name) + return p; + } + } + Property *property = pool()->New<Property>(); property->parent = this; property->_name = name; @@ -147,7 +151,10 @@ Property *QDeclarativeParser::Object::getProperty(const QHashedStringRef &name, properties.prepend(property); return property; } else { - return 0; + for (Property *p = properties.first(); p; p = properties.next(p)) { + if (p->name() == name) + return p; + } } } @@ -167,6 +174,7 @@ Property *QDeclarativeParser::Object::getProperty(const QString &name, bool crea Property *property = pool()->New<Property>(); property->parent = this; property->_name = QStringRef(pool()->NewString(name)); + propertiesHashField.testAndSet(property->_name.hash()); property->isDefault = false; properties.prepend(property); return property; |