fixed bad typing (int* instead of T*) and faster branchless codes

This commit is contained in:
Richard Thier 2024-09-03 03:34:49 +02:00
parent d2b4e5bf94
commit 04964cd2a0

View File

@ -35,7 +35,7 @@ class TurboList {
old = nex;
mid = end;
capacity *= 2;
nex = (int *) MALLOC(this->capacity * sizeof(T));
nex = (T *) MALLOC(this->capacity * sizeof(T));
// Will go into the INSERT code path here
return insert(elem);
@ -48,7 +48,7 @@ public:
end(initial_size),
capacity(initial_cap) {
nex = (int *) MALLOC(this->capacity * sizeof(T));
nex = (T *) MALLOC(this->capacity * sizeof(T));
}
inline ~TurboList() noexcept {
@ -57,7 +57,10 @@ public:
}
inline T& operator[](uint32_t i) noexcept {
return (i < mid) ? old[i] : nex[i];
// This seem to be more often compiled to cmov
// branchless conditional codes this way..
T *base = (i < mid) ? old : nex;
return base[i];
}
/** This is much faster than operator[] if you do small amounts of work per access */