added faster iteration via two loops

This commit is contained in:
Richard Thier 2024-08-28 13:16:13 +02:00
parent ca14a93f6f
commit 96aac6cc37

View File

@ -60,6 +60,18 @@ public:
return (i < mid) ? old[i] : nex[i]; 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 { inline void insert(T elem) noexcept {
if(TL_LIKELY(end < capacity)) { if(TL_LIKELY(end < capacity)) {