mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
rsx: simplify simple_array<T>::erase_if
This commit is contained in:
parent
f435225940
commit
d958f8291a
1 changed files with 12 additions and 5 deletions
|
@ -390,22 +390,29 @@ namespace rsx
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = false;
|
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))
|
if (predicate(*ptr))
|
||||||
{
|
{
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
if (ptr != last) // If not last
|
if (ptr == last)
|
||||||
{
|
{
|
||||||
// Move last item into current one
|
// Popping the last entry from list. Just set the new size and exit
|
||||||
std::memcpy(ptr, last, sizeof(Ty));
|
_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--;
|
_size--;
|
||||||
last--;
|
last--;
|
||||||
|
|
||||||
|
// Retest the same ptr which now has the previous tail item
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue