From 2fd765ba07d600d1838b2ee741c8e45c6669d06a Mon Sep 17 00:00:00 2001 From: Tobias Pankrath Date: Sun, 6 Sep 2020 21:42:56 +0200 Subject: [PATCH] ChoppedVector: short-circuit opApply for elements after m_length --- source/eventcore/internal/utils.d | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index 0973339..c4b72fe 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -187,11 +187,15 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { int opApply(scope int delegate(size_t idx, ref T) @safe nothrow del) { size_t idx = 0; + outer: foreach (c; m_chunks) { if (c) { - foreach (i, ref t; *c) + foreach (i, ref t; *c) { if (auto ret = del(idx+i, t)) return ret; + if (i + idx >= length) + break outer; + } } idx += chunkSize; } @@ -201,11 +205,15 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { int opApply(scope int delegate(size_t idx, ref const(T)) @safe nothrow del) const { size_t idx = 0; + outer: foreach (c; m_chunks) { if (c) { - foreach (i, ref t; *c) + foreach (i, ref t; *c) { if (auto ret = del(idx+i, t)) return ret; + if (i + idx >= length) + break outer; + } } idx += chunkSize; }