Merge pull request #159 from Panke/short-circuit
ChoppedVector: short-circuit opApply for elements after m_length
This commit is contained in:
commit
abc8af3bc5
|
@ -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)
|
int opApply(scope int delegate(size_t idx, ref T) @safe nothrow del)
|
||||||
{
|
{
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
|
outer:
|
||||||
foreach (c; m_chunks) {
|
foreach (c; m_chunks) {
|
||||||
if (c) {
|
if (c) {
|
||||||
foreach (i, ref t; *c)
|
foreach (i, ref t; *c) {
|
||||||
if (auto ret = del(idx+i, t))
|
if (auto ret = del(idx+i, t))
|
||||||
return ret;
|
return ret;
|
||||||
|
if (i + idx >= length)
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
idx += chunkSize;
|
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)
|
int opApply(scope int delegate(size_t idx, ref const(T)) @safe nothrow del)
|
||||||
const {
|
const {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
|
outer:
|
||||||
foreach (c; m_chunks) {
|
foreach (c; m_chunks) {
|
||||||
if (c) {
|
if (c) {
|
||||||
foreach (i, ref t; *c)
|
foreach (i, ref t; *c) {
|
||||||
if (auto ret = del(idx+i, t))
|
if (auto ret = del(idx+i, t))
|
||||||
return ret;
|
return ret;
|
||||||
|
if (i + idx >= length)
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
idx += chunkSize;
|
idx += chunkSize;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue