QMap - use hint on insert in QMap::toStdMap

Giving the std-map a hint (normally) improves insert performance.
There seems to be no reason not to provide this hint.

Change-Id: I4344607ebf54574a3ae9666d87a41a3c14762361
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-10-01 06:42:28 +02:00 committed by The Qt Project
parent 67a0f546c5
commit cfc3eeea1b
2 changed files with 13 additions and 1 deletions

View File

@ -946,7 +946,7 @@ Q_OUTOFLINE_TEMPLATE std::map<Key, T> QMap<Key, T>::toStdMap() const
const_iterator it = end();
while (it != begin()) {
--it;
map.insert(std::pair<Key, T>(it.key(), it.value()));
map.insert(map.begin(), std::pair<Key, T>(it.key(), it.value()));
}
return map;
}

View File

@ -60,6 +60,7 @@ private slots:
void lookup_string_int();
void iteration();
void toStdMap();
};
@ -159,6 +160,17 @@ void tst_QMap::iteration()
}
}
void tst_QMap::toStdMap()
{
QMap<int, int> map;
for (int i = 0; i < 100000; ++i)
map.insert(i, i);
QBENCHMARK {
std::map<int, int> n = map.toStdMap();
n.begin();
}
}
QTEST_MAIN(tst_QMap)