diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 642cf82f08..0e726e8394 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -946,7 +946,7 @@ Q_OUTOFLINE_TEMPLATE std::map QMap::toStdMap() const const_iterator it = end(); while (it != begin()) { --it; - map.insert(std::pair(it.key(), it.value())); + map.insert(map.begin(), std::pair(it.key(), it.value())); } return map; } diff --git a/tests/benchmarks/corelib/tools/qmap/main.cpp b/tests/benchmarks/corelib/tools/qmap/main.cpp index 05b52ba42f..c3b9c18cd2 100644 --- a/tests/benchmarks/corelib/tools/qmap/main.cpp +++ b/tests/benchmarks/corelib/tools/qmap/main.cpp @@ -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 map; + for (int i = 0; i < 100000; ++i) + map.insert(i, i); + + QBENCHMARK { + std::map n = map.toStdMap(); + n.begin(); + } +} QTEST_MAIN(tst_QMap)