diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-14 16:17:39 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-14 16:17:39 +1000 |
commit | 3ad5beee4c3fbbc855b84c8982c5458d634f1dee (patch) | |
tree | 7ddf1bcf379a16185c1c52f53bb689767122c1e9 /src/declarative/qml/v8/qhashedstring_p.h | |
parent | 7456055c2df733dbbe2ca5967f512c2555ca31d4 (diff) |
Performance improvements
There are two main changes here. First, where possible, we mark
properties as "IsDirect" which means that they exist in a C++
QMetaObject (as opposed to a dynamic meta object), which allows us
to call QObject::qt_metacall() directly, bypassing any dynamic meta
object stuff.
The second change is to use an ascii string comparator in V8 where
possible. V8 stores ASCII string internally as ASCII strings, and
asking it to compare them to a UTF16 string requires a conversion.
Diffstat (limited to 'src/declarative/qml/v8/qhashedstring_p.h')
-rw-r--r-- | src/declarative/qml/v8/qhashedstring_p.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/declarative/qml/v8/qhashedstring_p.h b/src/declarative/qml/v8/qhashedstring_p.h index ed00aea132..0dd111e189 100644 --- a/src/declarative/qml/v8/qhashedstring_p.h +++ b/src/declarative/qml/v8/qhashedstring_p.h @@ -137,11 +137,27 @@ class QStringHashNode { public: QStringHashNode(const QHashedString &key) - : nlist(0), next(0), key(key) {} + : nlist(0), next(0), key(key) { + if (isAscii()) ascii = key.toAscii(); + } QStringHashNode *nlist; QStringHashNode *next; QHashedString key; + QByteArray ascii; + + inline bool equals(v8::Handle<v8::String> string) { + return !ascii.isEmpty() && string->Equals((char*)ascii.constData(), ascii.length()) || + ascii.isEmpty() && string->Equals((uint16_t*)key.constData(), key.length()); + } +private: + bool isAscii() const { + for (int ii = 0; ii < key.length(); ++ii) { + if (key.at(ii) > 127) + return false; + } + return true; + } }; struct QStringHashData @@ -369,8 +385,7 @@ typename QStringHash<T>::Node *QStringHash<T>::findNode(const QHashedV8String &s quint32 hash = string.hash(); node = data.buckets[hash % data.numBuckets]; int length = string.length(); - while (node && (length != node->key.length() || hash != node->key.hash() || - !string.string()->Equals((uint16_t*)node->key.constData(), length))) + while (node && (length != node->key.length() || hash != node->key.hash() || !node->equals(string.string()))) node = node->next; } |