diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-12-23 22:35:21 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-12-25 18:10:08 +0100 |
commit | 20f0b58a24dabf17d5d1dcfc06eaa3ccafcd7268 (patch) | |
tree | db46cd8bc0ef16b3e4839ed48d7dc6958ba1973a | |
parent | 3ddb2344af8149b70861234eb36126b966e37c61 (diff) | |
download | qtwebchannel-20f0b58a24dabf17d5d1dcfc06eaa3ccafcd7268.tar.gz |
tst_webchannel: port from raw and shared pointers to unique_ptr
Avoids the need for qDeleteAll() in the case of raw pointers. Avoids
overhead for non-shared objects in the shared pointer case.
Since unique_ptr is a move-only type, use a container (std::vector)
and loop constuct (ranged for loop) that can handle it.
This removes the only use of QSharedPointer in this module.
Change-Id: Ic3fe90403eb3f28f1e2e370a3648bc522880a10d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Arno Rehn <a.rehn@menlosystems.com>
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index d628937..28f1482 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -20,6 +20,9 @@ #include <QtConcurrent> #endif +#include <memory> +#include <vector> + QT_USE_NAMESPACE #ifdef WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE @@ -1469,31 +1472,30 @@ void TestWebChannel::benchRegisterObjects() void TestWebChannel::benchRemoveTransport() { QWebChannel channel; - QList<DummyTransport*> dummyTransports; - for (int i = 500; i > 0; i--) - dummyTransports.append(new DummyTransport(this)); + std::vector<std::unique_ptr<DummyTransport>> dummyTransports(500); + for (auto &e : dummyTransports) + e = std::make_unique<DummyTransport>(this); - QList<QSharedPointer<TestObject>> objs; + std::vector<std::unique_ptr<TestObject>> objs; QMetaObjectPublisher *pub = channel.d_func()->publisher; - foreach (DummyTransport *transport, dummyTransports) { + for (auto &e : dummyTransports) { + DummyTransport *transport = e.get(); channel.connectTo(transport); channel.d_func()->publisher->initializeClient(transport); /* 30 objects per transport */ for (int i = 30; i > 0; i--) { - QSharedPointer<TestObject> obj = QSharedPointer<TestObject>::create(); - objs.append(obj); - pub->wrapResult(QVariant::fromValue(obj.data()), transport); + auto obj = std::make_unique<TestObject>(); + pub->wrapResult(QVariant::fromValue(obj.get()), transport); + objs.push_back(std::move(obj)); } } QBENCHMARK_ONCE { - for (auto transport : dummyTransports) - pub->transportRemoved(transport); + for (auto &transport : dummyTransports) + pub->transportRemoved(transport.get()); } - - qDeleteAll(dummyTransports); } #ifdef WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE |