Speed up QStringList::removeDuplicates by ~2x

QSet::contains needs to hash the string, which is unnecessary, since we
can just check if the size of the set changed.

Change-Id: I2c7a42bae6cdf351533d5a582a42079658fa7729
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
Daniel Teske 2014-09-05 11:51:01 +02:00
parent f5b53c8e3e
commit 46ebcb6176

View File

@ -751,11 +751,13 @@ int QtPrivate::QStringList_removeDuplicates(QStringList *that)
int j = 0;
QSet<QString> seen;
seen.reserve(n);
int setSize = 0;
for (int i = 0; i < n; ++i) {
const QString &s = that->at(i);
if (seen.contains(s))
continue;
seen.insert(s);
if (setSize == seen.size()) // unchanged size => was already seen
continue;
++setSize;
if (j != i)
that->swap(i, j);
++j;