Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f47c339e authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use std::erase_if to simplify removal of items

This function makes it simpler to remove items from collections. Update
our code to make it more readable.

Bug: 198472780
Test: presubmit

Change-Id: I3bc81bf729e9b22ced16691272187870783c1728
parent f60ade6b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ package {

cc_defaults {
    name: "inputflinger_defaults",
    cpp_std: "c++20",
    cflags: [
        "-Wall",
        "-Wextra",
+1 −2
Original line number Diff line number Diff line
@@ -71,8 +71,7 @@ public:

    void erase(const std::function<bool(const T&)>& lambda) {
        std::scoped_lock lock(mLock);
        mQueue.erase(std::remove_if(mQueue.begin(), mQueue.end(),
                [&lambda](const T& t) { return lambda(t); }), mQueue.end());
        std::erase_if(mQueue, [&lambda](const auto& t) { return lambda(t); });
    }

    /**
+2 −4
Original line number Diff line number Diff line
@@ -106,10 +106,8 @@ void TouchState::filterNonAsIsTouchWindows() {
}

void TouchState::filterWindowsExcept(const sp<IBinder>& token) {
    auto it = std::remove_if(windows.begin(), windows.end(), [&token](const TouchedWindow& w) {
        return w.windowHandle->getToken() != token;
    });
    windows.erase(it, windows.end());
    std::erase_if(windows,
                  [&token](const TouchedWindow& w) { return w.windowHandle->getToken() != token; });
}

sp<WindowInfoHandle> TouchState::getFirstForegroundWindowHandle() const {
+4 −7
Original line number Diff line number Diff line
@@ -2344,13 +2344,10 @@ void EventHub::closeVideoDeviceByPathLocked(const std::string& devicePath) {
            return;
        }
    }
    mUnattachedVideoDevices
            .erase(std::remove_if(mUnattachedVideoDevices.begin(), mUnattachedVideoDevices.end(),
                                  [&devicePath](
                                          const std::unique_ptr<TouchVideoDevice>& videoDevice) {
    std::erase_if(mUnattachedVideoDevices,
                  [&devicePath](const std::unique_ptr<TouchVideoDevice>& videoDevice) {
                      return videoDevice->getPath() == devicePath;
                                  }),
                   mUnattachedVideoDevices.end());
                  });
}

void EventHub::closeAllDevicesLocked() {
+1 −3
Original line number Diff line number Diff line
@@ -237,9 +237,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
    auto mapIt = mDeviceToEventHubIdsMap.find(device);
    if (mapIt != mDeviceToEventHubIdsMap.end()) {
        std::vector<int32_t>& eventHubIds = mapIt->second;
        eventHubIds.erase(std::remove_if(eventHubIds.begin(), eventHubIds.end(),
                                         [eventHubId](int32_t eId) { return eId == eventHubId; }),
                          eventHubIds.end());
        std::erase_if(eventHubIds, [eventHubId](int32_t eId) { return eId == eventHubId; });
        if (eventHubIds.size() == 0) {
            mDeviceToEventHubIdsMap.erase(mapIt);
        }