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:
parent
67a0f546c5
commit
cfc3eeea1b
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user