From 5b38f061dcb75e349c2d57c193bbaf46d9cd02ef Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 10 Jul 2019 15:41:50 -0700 Subject: [PATCH] Use std::set instead of SortedVector Avoid the use of custom data structures. Here, convert disabledInputDevices into set. We only care about whether or not a certain input device is present in this list. Bug: 137212522 Test: none Change-Id: I761a6e0165a7ce937e241c30a40249edd0810376 --- .../com_android_server_input_InputManagerService.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 1c8c46c740026..466ca9315f6f0 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include @@ -307,7 +306,7 @@ private: wp pointerController; // Input devices to be disabled - SortedVector disabledInputDevices; + std::set disabledInputDevices; // Associated Pointer controller display. int32_t pointerDisplayId; @@ -898,13 +897,13 @@ void NativeInputManager::setInputDeviceEnabled(uint32_t deviceId, bool enabled) { // acquire lock AutoMutex _l(mLock); - ssize_t index = mLocked.disabledInputDevices.indexOf(deviceId); - bool currentlyEnabled = index < 0; + auto it = mLocked.disabledInputDevices.find(deviceId); + bool currentlyEnabled = it == mLocked.disabledInputDevices.end(); if (!enabled && currentlyEnabled) { - mLocked.disabledInputDevices.add(deviceId); + mLocked.disabledInputDevices.insert(deviceId); } if (enabled && !currentlyEnabled) { - mLocked.disabledInputDevices.remove(deviceId); + mLocked.disabledInputDevices.erase(deviceId); } } // release lock