Skip to content

Commit

Permalink
IdList::RemoveTagged switch to std::remove_if from iteration. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpavlik authored and whitequark committed Aug 20, 2019
1 parent 3ea077b commit 0bb6a34
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/dsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,24 +474,22 @@ class IdList {
}

void RemoveTagged() {
int src, dest;
dest = 0;
for(src = 0; src < n; src++) {
if(elem[src].tag) {
// this item should be deleted
elem[src].Clear();
} else {
if(src != dest) {
elem[dest] = elem[src];
}
dest++;
auto newEnd = std::remove_if(this->begin(), this->end(), [](T &t) {
if(t.tag) {
t.Clear();
return true;
}
return false;
});
if(newEnd != this->end()) {
while (newEnd != this->end()) {
newEnd->~T();
++newEnd;
}
}
for(int i = dest; i < n; i++)
elem[i].~T();
n = dest;
// and elemsAllocated is untouched, because we didn't resize
n = newEnd - begin();
}

void RemoveById(H h) {
ClearTags();
FindById(h)->tag = 1;
Expand Down

0 comments on commit 0bb6a34

Please sign in to comment.