From: Lars Knoll Date: Fri, 28 Jun 2013 06:25:05 +0000 (+0200) Subject: Reuse the hash value inside identifier to hash them X-Git-Tag: upstream/5.2.1~669^2~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc9c9ca653796582b5faacb5415d12fd71d036f1;p=platform%2Fupstream%2Fqtdeclarative.git Reuse the hash value inside identifier to hash them Hashing on the pointer value of an identifier doesn't really make sense. We already have a good hash value for the identifier, so let's re-use it. In addition, this allows to look up strings that aren't identifiers. Change-Id: I9bdb4aa89ae36410f24b3e58c641339e115e4c5f Reviewed-by: Simon Hausmann --- diff --git a/src/qml/qml/v4/qv4identifier.cpp b/src/qml/qml/v4/qv4identifier.cpp index 1a078bb..4e66e48 100644 --- a/src/qml/qml/v4/qv4identifier.cpp +++ b/src/qml/qml/v4/qv4identifier.cpp @@ -87,7 +87,7 @@ IdentifierHashEntry *IdentifierHashBase::addEntry(const Identifier *identifier) const IdentifierHashEntry &e = d->entries[i]; if (!e.identifier) continue; - uint idx = Identifier::hash(e.identifier) % newAlloc; + uint idx = e.identifier->hashValue % newAlloc; while (newEntries[idx].identifier) { ++idx; idx %= newAlloc; @@ -99,7 +99,7 @@ IdentifierHashEntry *IdentifierHashBase::addEntry(const Identifier *identifier) d->alloc = newAlloc; } - uint idx = Identifier::hash(identifier) % d->alloc; + uint idx = identifier->hashValue % d->alloc; while (d->entries[idx].identifier) { Q_ASSERT(d->entries[idx].identifier != identifier); ++idx; @@ -116,12 +116,12 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(const Identifier *identifi return 0; assert(d->entries); - uint idx = Identifier::hash(identifier) % d->alloc; + uint idx = identifier->hashValue % d->alloc; while (1) { - if (d->entries[idx].identifier == identifier) - return d->entries + idx; if (!d->entries[idx].identifier) return 0; + if (d->entries[idx].identifier == identifier) + return d->entries + idx; ++idx; idx %= d->alloc; } @@ -131,14 +131,27 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(const QString &str) const { if (!d) return 0; - return lookup(d->identifierTable->identifier(str)); + assert(d->entries); + + uint hash = String::createHashValue(str.constData(), str.length()); + uint idx = hash % d->alloc; + while (1) { + if (!d->entries[idx].identifier) + return 0; + if (d->entries[idx].identifier->string == str) + return d->entries + idx; + ++idx; + idx %= d->alloc; + } } const IdentifierHashEntry *IdentifierHashBase::lookup(String *str) const { if (!d) return 0; - return lookup(d->identifierTable->identifier(str)); + if (str->identifier) + return lookup(str->identifier); + return lookup(str->toQString()); } const Identifier *IdentifierHashBase::toIdentifier(const QString &str) const diff --git a/src/qml/qml/v4/qv4identifier_p.h b/src/qml/qml/v4/qv4identifier_p.h index 35f4d17..250f4be 100644 --- a/src/qml/qml/v4/qv4identifier_p.h +++ b/src/qml/qml/v4/qv4identifier_p.h @@ -55,15 +55,6 @@ struct Identifier { QString string; uint hashValue; - - static inline uint hash(const QV4::Identifier *id) - { - quintptr h = (quintptr)id; - if (sizeof(quintptr) == sizeof(uint)) - return h ^ (h >> 8); - else - return (uint)(h ^ (h >> 8) ^ (h >> 32)); - } }; diff --git a/src/qml/qml/v4/qv4internalclass.cpp b/src/qml/qml/v4/qv4internalclass.cpp index 043e623..635b796 100644 --- a/src/qml/qml/v4/qv4internalclass.cpp +++ b/src/qml/qml/v4/qv4internalclass.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE uint QV4::qHash(const QV4::InternalClassTransition &t, uint) { - return Identifier::hash(t.id) ^ t.flags; + return t.id->hashValue ^ t.flags; } using namespace QV4; @@ -91,7 +91,7 @@ void PropertyHash::addEntry(const PropertyHash::Entry &entry, int classSize) const Entry &e = d->entries[i]; if (!e.identifier || e.index >= classSize) continue; - uint idx = Identifier::hash(e.identifier) % dd->alloc; + uint idx = e.identifier->hashValue % dd->alloc; while (dd->entries[idx].identifier) { ++idx; idx %= dd->alloc; @@ -104,7 +104,7 @@ void PropertyHash::addEntry(const PropertyHash::Entry &entry, int classSize) d = dd; } - uint idx = Identifier::hash(entry.identifier) % d->alloc; + uint idx = entry.identifier->hashValue % d->alloc; while (d->entries[idx].identifier) { ++idx; idx %= d->alloc; @@ -117,7 +117,7 @@ uint PropertyHash::lookup(const Identifier *identifier) const { assert(d->entries); - uint idx = Identifier::hash(identifier) % d->alloc; + uint idx = identifier->hashValue % d->alloc; while (1) { if (d->entries[idx].identifier == identifier) return d->entries[idx].index;