From 2b12b5c970202ca4e584f44ebdb0e29b79cf650f Mon Sep 17 00:00:00 2001 From: masterexplorer Date: Tue, 27 Aug 2024 10:53:44 +0200 Subject: [PATCH] optimized operator[] (branchless) --- TurboList.hpp | 6 +----- main.cpp | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/TurboList.hpp b/TurboList.hpp index 45beed0..f221e6b 100644 --- a/TurboList.hpp +++ b/TurboList.hpp @@ -31,11 +31,7 @@ public: } inline int& operator[](uint32_t i) noexcept { - if(i < mid) { - return old[i]; - } else { - return nex[i]; - } + return (i < mid) ? old[i] : nex[i]; } inline void insert(int elem) noexcept { diff --git a/main.cpp b/main.cpp index fd3c63f..92d0aec 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,7 @@ #include"TurboList.hpp" // #define PRINT_DBG +// #define N 65535 #define N 65535000 static inline size_t ms_now() noexcept {