summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/input/evdevtablet
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-08 12:00:05 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-12 13:43:52 +0200
commit3bc10fb9bb930c4e1baf52f9d0ba97616e8e77f6 (patch)
treeb6b3c30e5d0be24fb9e694020478e318b8f93656 /src/platformsupport/input/evdevtablet
parent12938ba70b1277c15cf58eb7f56b58ab37e08849 (diff)
QEvdev: Replace manual memory management with unique_ptr
Make create() return, and m_mice/m_keyboards/etc store, handlers by unique_ptr. In most cases, we can't use qt_make_unique(), since the ctor we're calling is marked as private. Since QHash can't hold move-only types, use a std::vector<{QString, unique_ptr}> instead. As this pattern repeats in all four QEvdev*Manager classes, create a small class template. Saves almost 6KiB on optimized Linux AMD64 GCC 9.1 builds across all .so's that link to QtInputSupport.a. Change-Id: I8f62b6b629d6e1855314c0a4fb4fc069db9ae0ce Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/platformsupport/input/evdevtablet')
-rw-r--r--src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp12
-rw-r--r--src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h4
2 files changed, 7 insertions, 9 deletions
diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
index eedde9a96e..d503476aad 100644
--- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
+++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
@@ -46,6 +46,7 @@
#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
#include <private/qguiapplication_p.h>
#include <private/qinputdevicemanager_p_p.h>
+#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
@@ -99,16 +100,14 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec
QEvdevTabletManager::~QEvdevTabletManager()
{
- qDeleteAll(m_activeDevices);
}
void QEvdevTabletManager::addDevice(const QString &deviceNode)
{
qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode));
- QEvdevTabletHandlerThread *handler;
- handler = new QEvdevTabletHandlerThread(deviceNode, m_spec);
+ auto handler = qt_make_unique<QEvdevTabletHandlerThread>(deviceNode, m_spec);
if (handler) {
- m_activeDevices.insert(deviceNode, handler);
+ m_activeDevices.add(deviceNode, std::move(handler));
updateDeviceCount();
} else {
qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode));
@@ -117,12 +116,9 @@ void QEvdevTabletManager::addDevice(const QString &deviceNode)
void QEvdevTabletManager::removeDevice(const QString &deviceNode)
{
- if (m_activeDevices.contains(deviceNode)) {
+ if (m_activeDevices.remove(deviceNode)) {
qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode));
- QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode);
- m_activeDevices.remove(deviceNode);
updateDeviceCount();
- delete handler;
}
}
diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h b/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h
index 5178e167b0..0274f9d3ed 100644
--- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h
+++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h
@@ -51,6 +51,8 @@
// We mean it.
//
+#include <QtInputSupport/private/devicehandlerlist_p.h>
+
#include <QObject>
#include <QHash>
#include <QSocketNotifier>
@@ -74,7 +76,7 @@ private:
QString m_spec;
QDeviceDiscovery *m_deviceDiscovery;
- QHash<QString, QEvdevTabletHandlerThread *> m_activeDevices;
+ QtInputSupport::DeviceHandlerList<QEvdevTabletHandlerThread> m_activeDevices;
};
QT_END_NAMESPACE