mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 13:31:27 +12:00
rsx/util: Change the filter function to an in-place erase-if operation
This commit is contained in:
parent
b94ddb0cd3
commit
109b841d8d
1 changed files with 7 additions and 3 deletions
|
@ -382,22 +382,26 @@ namespace rsx
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void filter(std::predicate<const Ty&> auto predicate)
|
bool erase_if(std::predicate<const Ty&> auto predicate)
|
||||||
{
|
{
|
||||||
if (!_size)
|
if (!_size)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
for (auto ptr = _data, last = _data + _size - 1; ptr < last; ptr++)
|
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
|
// Move item to the end of the list and shrink by 1
|
||||||
std::memcpy(ptr, last, sizeof(Ty));
|
std::memcpy(ptr, last, sizeof(Ty));
|
||||||
last = _data + (--_size);
|
last = _data + (--_size);
|
||||||
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort(std::predicate<const Ty&, const Ty&> auto predicate)
|
void sort(std::predicate<const Ty&, const Ty&> auto predicate)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue