From 96aac6cc377f1e7841c1d69ba9eb7d50ff745456 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Wed, 28 Aug 2024 13:16:13 +0200 Subject: [PATCH] added faster iteration via two loops --- TurboList.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TurboList.hpp b/TurboList.hpp index 323c547..7bd6bbd 100644 --- a/TurboList.hpp +++ b/TurboList.hpp @@ -60,6 +60,18 @@ public: return (i < mid) ? old[i] : nex[i]; } + /** This is much faster than operator[] if you do small amounts of work per access */ + inline void iterate(void(callback)(T&)) noexcept { + // old + for(uint32_t i = 0; i < mid; ++i) { + callback(old[i]); + } + // nex + for(uint32_t i = mid; i < end; ++i) { + callback(nex[i]); + } + } + inline void insert(T elem) noexcept { if(TL_LIKELY(end < capacity)) {