Simplify IdList::Add(). NFC.
Offloads most of the work onto standard algorithms to make it more self-evidently correct.pull/459/head
parent
3340392bf0
commit
60fdac141d
18
src/dsc.h
18
src/dsc.h
|
@ -399,16 +399,14 @@ public:
|
||||||
if(n >= elemsAllocated) {
|
if(n >= elemsAllocated) {
|
||||||
ReserveMore((elemsAllocated + 32)*2 - n);
|
ReserveMore((elemsAllocated + 32)*2 - n);
|
||||||
}
|
}
|
||||||
auto newIndex = LowerBoundIndex(*t);
|
// Look to see if we already have something with the same handle value.
|
||||||
if (newIndex < n) {
|
ssassert(FindByIdNoOops(t->h) == nullptr, "Handle isn't unique");
|
||||||
H hm = elem[newIndex].h;
|
|
||||||
ssassert(hm.v != t->h.v, "Handle isn't unique");
|
// Copy-construct at the end of the list.
|
||||||
}
|
new(&elem[n]) T(*t);
|
||||||
int i = static_cast<int>(newIndex);
|
++n;
|
||||||
new(&elem[n]) T();
|
// The item we just added is trivially sorted, so "merge"
|
||||||
std::move_backward(elem + i, elem + n, elem + n + 1);
|
std::inplace_merge(begin(), end() - 1, end(), Compare());
|
||||||
elem[i] = *t;
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T *FindById(H h) {
|
T *FindById(H h) {
|
||||||
|
|
Loading…
Reference in New Issue