Fix pathologically slow translate groups on Linux

Major performance improvement on GCC with libstdc++.
pull/978/head
Přemysl Eric Janouch 2021-03-27 14:48:31 +01:00 committed by phkahler
parent d511ce4acc
commit 5e42275b1a
1 changed files with 10 additions and 4 deletions

View File

@ -467,11 +467,17 @@ public:
// Look to see if we already have something with the same handle value.
ssassert(FindByIdNoOops(t->h) == nullptr, "Handle isn't unique");
// Copy-construct at the end of the list.
new(&elem[n]) T(*t);
// Find out where the added element should be.
int pos = LowerBoundIndex(*t);
// Shift everything from there to the end of the array.
new(&elem[n]) T();
for (int i = n; i > pos; i--)
elem[i] = std::move(elem[i - 1]);
// Copy-construct at the right place.
elem[pos] = T(*t);
++n;
// The item we just added is trivially sorted, so "merge"
std::inplace_merge(begin(), end() - 1, end(), Compare());
}
T *FindById(H h) {