QMap - improve QMap stl-map ctor
We can insert directly on the most left-most Node. We always enforce an insert here (unlike the insert call), but that is not a problem since the keys in a std::map are unique. Change-Id: Ib409b90ffc57a5a43dab4a4b08d34f6fdabd057f Reviewed-by: Lars Knoll <lars.knoll@digia.com>bb10
parent
3a333f2d92
commit
af437047a2
|
|
@ -939,7 +939,7 @@ Q_OUTOFLINE_TEMPLATE QMap<Key, T>::QMap(const std::map<Key, T> &other)
|
|||
typename std::map<Key,T>::const_iterator it = other.end();
|
||||
while (it != other.begin()) {
|
||||
--it;
|
||||
insert((*it).first, (*it).second);
|
||||
d->createNode((*it).first, (*it).second, d->begin(), true); // insert on most left node.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ protected:
|
|||
public slots:
|
||||
void init();
|
||||
private slots:
|
||||
void ctor();
|
||||
void count();
|
||||
void clear();
|
||||
void beginEnd();
|
||||
|
|
@ -146,6 +147,30 @@ void tst_QMap::init()
|
|||
MyClass::count = 0;
|
||||
}
|
||||
|
||||
void tst_QMap::ctor()
|
||||
{
|
||||
std::map<int, int> map;
|
||||
for (int i = 0; i < 100000; ++i)
|
||||
map.insert(std::pair<int, int>(i * 3, i * 7));
|
||||
|
||||
QMap<int, int> qmap(map); // ctor.
|
||||
|
||||
// Check that we have the same
|
||||
std::map<int, int>::iterator j = map.begin();
|
||||
QMap<int, int>::const_iterator i = qmap.constBegin();
|
||||
|
||||
while (i != qmap.constEnd()) {
|
||||
QCOMPARE( (*j).first, i.key());
|
||||
QCOMPARE( (*j).second, i.value());
|
||||
++i;
|
||||
++j;
|
||||
}
|
||||
|
||||
QCOMPARE( (int) map.size(), qmap.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tst_QMap::count()
|
||||
{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ private slots:
|
|||
void iteration();
|
||||
void toStdMap();
|
||||
void iterator_begin();
|
||||
|
||||
void ctorStdMap();
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -189,6 +191,19 @@ void tst_QMap::iterator_begin()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QMap::ctorStdMap()
|
||||
{
|
||||
std::map<int, int> map;
|
||||
for (int i = 0; i < 100000; ++i)
|
||||
map.insert(std::pair<int, int>(i, i));
|
||||
|
||||
QBENCHMARK {
|
||||
QMap<int, int> qmap(map);
|
||||
qmap.constBegin();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QMap)
|
||||
|
||||
#include "main.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue