Eliding of slice range checking
Per Nordlöw
per.nordlow at gmail.com
Wed Oct 23 11:20:59 UTC 2019
Does DMD/LDC avoid range-checking in slice-expressions such as
the one in my array-overload of `startsWith` defined as
bool startsWith(T)(scope const(T)[] haystack,
scope const(T)[] needle)
{
if (haystack.length >= needle.length)
{
return haystack[0 .. needle.length] == needle; // is
slice range checking avoid here?
}
return false;
}
///
@safe pure nothrow @nogc unittest
{
auto x = "beta version";
assert(x.startsWith("beta"));
}
when building in release mode?
I remember a DMD pull from Ian Buclaw that enabled some eliding
but I don't remember if it includes the case above.
How can I investigate the codegen myself here?
More information about the Digitalmars-d-learn
mailing list