Add IdList::AllocForOneMore() based on List. NFC.
Also modifies a sizeof call.pull/459/head
parent
0bfbbe2bf3
commit
9fd09ddd8a
15
src/dsc.h
15
src/dsc.h
|
@ -215,7 +215,7 @@ public:
|
||||||
void ReserveMore(int howMuch) {
|
void ReserveMore(int howMuch) {
|
||||||
if(n + howMuch > elemsAllocated) {
|
if(n + howMuch > elemsAllocated) {
|
||||||
elemsAllocated = n + howMuch;
|
elemsAllocated = n + howMuch;
|
||||||
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(elem[0]));
|
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(T));
|
||||||
for(int i = 0; i < n; i++) {
|
for(int i = 0; i < n; i++) {
|
||||||
new(&newElem[i]) T(std::move(elem[i]));
|
new(&newElem[i]) T(std::move(elem[i]));
|
||||||
elem[i].~T();
|
elem[i].~T();
|
||||||
|
@ -348,6 +348,12 @@ public:
|
||||||
return n == 0;
|
return n == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AllocForOneMore() {
|
||||||
|
if(n >= elemsAllocated) {
|
||||||
|
ReserveMore((elemsAllocated + 32)*2 - n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t MaximumId() {
|
uint32_t MaximumId() {
|
||||||
if(IsEmpty()) {
|
if(IsEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -391,7 +397,7 @@ public:
|
||||||
void ReserveMore(int howMuch) {
|
void ReserveMore(int howMuch) {
|
||||||
if(n + howMuch > elemsAllocated) {
|
if(n + howMuch > elemsAllocated) {
|
||||||
elemsAllocated = n + howMuch;
|
elemsAllocated = n + howMuch;
|
||||||
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(elem[0]));
|
T *newElem = (T *)MemAlloc((size_t)elemsAllocated*sizeof(T));
|
||||||
for(int i = 0; i < n; i++) {
|
for(int i = 0; i < n; i++) {
|
||||||
new(&newElem[i]) T(std::move(elem[i]));
|
new(&newElem[i]) T(std::move(elem[i]));
|
||||||
elem[i].~T();
|
elem[i].~T();
|
||||||
|
@ -402,9 +408,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void Add(T *t) {
|
void Add(T *t) {
|
||||||
if(n >= elemsAllocated) {
|
AllocForOneMore();
|
||||||
ReserveMore((elemsAllocated + 32)*2 - n);
|
|
||||||
}
|
|
||||||
// Look to see if we already have something with the same handle value.
|
// Look to see if we already have something with the same handle value.
|
||||||
ssassert(FindByIdNoOops(t->h) == nullptr, "Handle isn't unique");
|
ssassert(FindByIdNoOops(t->h) == nullptr, "Handle isn't unique");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue