Compare all available lengths prior to entering the loop

This commit is contained in:
Andrei Alexandrescu 2021-10-15 16:01:29 -04:00
parent 963274f1c1
commit c21f0ea8eb

View file

@ -1003,10 +1003,23 @@ template equal(alias pred = "a == b")
} }
else else
{ {
static if (allSatisfy!(hasLength, Ranges)) static foreach (i, R; Ranges)
static foreach (r; rs[1 .. $]) {
if (rs[0].length != r.length) static if (hasLength!R)
{
static if (!is(typeof(firstWithLength)))
{
// Found the first range that has length
enum firstWithLength = i;
}
else
{
// Compare the length of the current range against the first with length
if (rs[firstWithLength].length != rs[i].length)
return false; return false;
}
}
}
return equalLoop(rs); return equalLoop(rs);
} }
} }