From 109b841d8df535026cda35c6105ba584f37a24c9 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 3 Nov 2024 04:17:26 +0300 Subject: [PATCH] rsx/util: Change the filter function to an in-place erase-if operation --- rpcs3/Emu/RSX/Common/simple_array.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index e6f1819ad3..7bb00f2683 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -382,22 +382,26 @@ namespace rsx return false; } - void filter(std::predicate auto predicate) + bool erase_if(std::predicate auto predicate) { if (!_size) { - return; + return false; } + bool ret = false; for (auto ptr = _data, last = _data + _size - 1; ptr < last; ptr++) { - if (!predicate(*ptr)) + if (predicate(*ptr)) { // Move item to the end of the list and shrink by 1 std::memcpy(ptr, last, sizeof(Ty)); last = _data + (--_size); + ret = true; } } + + return ret; } void sort(std::predicate auto predicate)