From 3a02ba32e8a708069373823ed301a037987ed87d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 22 Jan 2022 23:18:19 -0800 Subject: Avoid a messy while loop to remove from a vector --- alc/backends/pipewire.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 120e3af6..41949a9b 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -1104,18 +1104,15 @@ void EventManager::removeCallback(uint32_t id) { DeviceNode::Remove(id); - auto elem = mNodeList.begin(); - while(elem != mNodeList.end()) + auto clear_node = [id](NodeProxy *node) noexcept { - NodeProxy *node{*elem}; - if(node->mId == id) - { - al::destroy_at(node); - elem = mNodeList.erase(elem); - continue; - } - ++elem; - } + if(node->mId != id) + return false; + al::destroy_at(node); + return true; + }; + auto node_end = std::remove_if(mNodeList.begin(), mNodeList.end(), clear_node); + mNodeList.erase(node_end, mNodeList.end()); if(mDefaultMetadata && mDefaultMetadata->mId == id) { -- cgit v1.2.3