From 04964cd2a0f71c67916abfc976387afef8f14158 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 3 Sep 2024 03:34:49 +0200 Subject: [PATCH] fixed bad typing (int* instead of T*) and faster branchless codes --- TurboList.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TurboList.hpp b/TurboList.hpp index 7646118..fdb93ca 100644 --- a/TurboList.hpp +++ b/TurboList.hpp @@ -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 */