From d958f8291a66043ce6d9a19f46e830e7aa951d34 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 26 Apr 2025 19:19:28 +0300 Subject: [PATCH] rsx: simplify simple_array::erase_if --- rpcs3/Emu/RSX/Common/simple_array.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index a567253f74..08bb97cb86 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -390,22 +390,29 @@ namespace rsx } bool ret = false; - for (auto last = _data + (_size - 1), ptr = last; ptr >= _data; ptr--) + for (auto ptr = _data, last = _data + _size - 1; ptr <= last;) { if (predicate(*ptr)) { ret = true; - if (ptr != last) // If not last + if (ptr == last) { - // Move last item into current one - std::memcpy(ptr, last, sizeof(Ty)); + // Popping the last entry from list. Just set the new size and exit + _size--; + break; } - // Pop last entry from list and set new last item + // Move item to the end of the list and shrink by 1 + std::memcpy(ptr, last, sizeof(Ty)); _size--; last--; + + // Retest the same ptr which now has the previous tail item + continue; } + + ptr++; } return ret;