diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-04-15 19:12:34 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-04-15 20:16:33 (GMT) |
commit | 2c0f13ccfe750241eb7ddedf6412da380a146975 (patch) | |
tree | ff75556c7c677d10114b7d4f95f5a8fe65fa306c /tools/linguist/lupdate/cpp.cpp | |
parent | 32aadef3a6621843fe065c3a5f2834a528a7d6fb (diff) | |
download | Qt-2c0f13ccfe750241eb7ddedf6412da380a146975.zip Qt-2c0f13ccfe750241eb7ddedf6412da380a146975.tar.gz Qt-2c0f13ccfe750241eb7ddedf6412da380a146975.tar.bz2 |
make HashString and HashStringList objects smaller
qHash(QString) has only 28 bits, so we can use the upper bits
for flagging whether the hash is valid.
size effect:
LP32: align(4, 4 + 4 + 1) = 12 vs. align(4, 4 + 4) = 8
LP64: align(8, 8 + 8 + 1) = 24 vs. align(8, 8 + 8) = 16
P64: align(8, 8 + 4 + 1) = 16 vs. align(8, 8 + 4) = 16
Diffstat (limited to 'tools/linguist/lupdate/cpp.cpp')
-rw-r--r-- | tools/linguist/lupdate/cpp.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 66a079a..3422212 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -65,47 +65,44 @@ static QString MagicComment(QLatin1String("TRANSLATOR")); class HashString { public: - HashString() : m_hashed(false) {} - explicit HashString(const QString &str) : m_str(str), m_hashed(false) {} - void setValue(const QString &str) { m_str = str; m_hashed = false; } + HashString() : m_hash(0x80000000) {} + explicit HashString(const QString &str) : m_str(str), m_hash(0x80000000) {} + void setValue(const QString &str) { m_str = str; m_hash = 0x80000000; } const QString &value() const { return m_str; } bool operator==(const HashString &other) const { return m_str == other.m_str; } private: QString m_str; + // qHash() of a QString is only 28 bits wide, so we can use + // the highest bit(s) as the "hash valid" flag. mutable uint m_hash; - mutable bool m_hashed; friend uint qHash(const HashString &str); }; uint qHash(const HashString &str) { - if (!str.m_hashed) { - str.m_hashed = true; + if (str.m_hash & 0x80000000) str.m_hash = qHash(str.m_str); - } return str.m_hash; } class HashStringList { public: - explicit HashStringList(const QList<HashString> &list) : m_list(list), m_hashed(false) {} + explicit HashStringList(const QList<HashString> &list) : m_list(list), m_hash(0x80000000) {} const QList<HashString> &value() const { return m_list; } bool operator==(const HashStringList &other) const { return m_list == other.m_list; } private: QList<HashString> m_list; mutable uint m_hash; - mutable bool m_hashed; friend uint qHash(const HashStringList &list); }; uint qHash(const HashStringList &list) { - if (!list.m_hashed) { - list.m_hashed = true; + if (list.m_hash & 0x80000000) { uint hash = 0; foreach (const HashString &qs, list.m_list) { - hash ^= qHash(qs) ^ 0xa09df22f; - hash = (hash << 13) | (hash >> 19); + hash ^= qHash(qs) ^ 0x0ad9f526; + hash = ((hash << 13) & 0x0fffffff) | (hash >> 15); } list.m_hash = hash; } |