From 640672be477419b591c25da57172f53bd71257df Mon Sep 17 00:00:00 2001 From: masterexplorer Date: Tue, 27 Aug 2024 11:20:20 +0200 Subject: [PATCH] branchless optimization --- TurboList.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TurboList.hpp b/TurboList.hpp index 9975724..8092ef2 100644 --- a/TurboList.hpp +++ b/TurboList.hpp @@ -61,14 +61,22 @@ public: inline void insert(int elem) noexcept { if(TL_LIKELY(count < capacity)) { // INSERT + + /* Same as this: if(mid > 0) { nex[mid - 1] = old[mid - 1]; --mid; } + */ + bool hasmid = (mid > 0); + mid -= hasmid; + nex[mid] = hasmid ? old[mid] : nex[mid]; + nex[end++] = elem; ++count; } else { // GROW + grow_and_insert(elem); } }