diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-01 10:26:03 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-02 07:56:07 (GMT) |
commit | 4e036ebbc6351a9bd6597e89a803f5c4de746092 (patch) | |
tree | 48a71f414575e6088b9a60b5e8d669fea3390815 | |
parent | 88482ebf36a5fdd0cfaa24c7029b42e19090c6f0 (diff) | |
download | Qt-4e036ebbc6351a9bd6597e89a803f5c4de746092.zip Qt-4e036ebbc6351a9bd6597e89a803f5c4de746092.tar.gz Qt-4e036ebbc6351a9bd6597e89a803f5c4de746092.tar.bz2 |
optimize duplicate resolution
use pointers in the index hash to avoid needless allocs and copies
-rw-r--r-- | tools/linguist/shared/translator.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 3721204..9ac1dd8 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -416,25 +416,46 @@ void Translator::dropTranslations() } } +struct TranslatorMessagePtr { + TranslatorMessagePtr(const TranslatorMessage &tm) + { + ptr = &tm; + } + + const TranslatorMessage *ptr; +}; + +Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE); + +static inline int qHash(TranslatorMessagePtr tmp) +{ + return qHash(*tmp.ptr); +} + +static inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2) +{ + return *tmp1.ptr == *tmp2.ptr; +} + QList<TranslatorMessage> Translator::findDuplicates() const { - QHash<TranslatorMessage, int> dups; + QHash<TranslatorMessagePtr, int> dups; foreach (const TranslatorMessage &msg, m_messages) dups[msg]++; QList<TranslatorMessage> ret; - QHash<TranslatorMessage, int>::ConstIterator it = dups.constBegin(), end = dups.constEnd(); + QHash<TranslatorMessagePtr, int>::ConstIterator it = dups.constBegin(), end = dups.constEnd(); for (; it != end; ++it) if (it.value() > 1) - ret.append(it.key()); + ret.append(*it.key().ptr); return ret; } void Translator::resolveDualEncoded() { - QHash<TranslatorMessage, int> dups; + QHash<TranslatorMessagePtr, int> dups; for (int i = 0; i < m_messages.count();) { const TranslatorMessage &msg = m_messages.at(i); - QHash<TranslatorMessage, int>::ConstIterator it = dups.constFind(msg); + QHash<TranslatorMessagePtr, int>::ConstIterator it = dups.constFind(msg); if (it != dups.constEnd()) { TranslatorMessage &omsg = m_messages[*it]; if (omsg.isUtf8() != msg.isUtf8() && !omsg.isNonUtf8()) { |