diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-06-28 08:25:05 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-28 14:56:31 +0200 |
commit | bc9c9ca653796582b5faacb5415d12fd71d036f1 (patch) | |
tree | 8876e178834caee6fecdee864857008da7ec515b /src/qml/qml/v4 | |
parent | 8dab9e5d118c9a0d6d180a44aaa8f7c3a1108ae2 (diff) |
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 <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/v4')
-rw-r--r-- | src/qml/qml/v4/qv4identifier.cpp | 27 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4identifier_p.h | 9 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4internalclass.cpp | 8 |
3 files changed, 24 insertions, 20 deletions
diff --git a/src/qml/qml/v4/qv4identifier.cpp b/src/qml/qml/v4/qv4identifier.cpp index 1a078bb015..4e66e48194 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 35f4d17b05..250f4bece0 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 043e6238a0..635b796dd8 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; |