[Issue 13381] One case of array literal that can be stack-allocated
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 31 03:07:39 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13381
--- Comment #2 from bearophile_hugs at eml.cc ---
Given this code:
void foo(uint[] a) @nogc {
if (a == [1, 2]) {}
}
One way to rewrite it is (the immutable can't be always used):
void foo(uint[] a) @nogc {
immutable static uint[2] __foo_aux0 == [1, 2];
if (a == __foo_aux0) {}
}
Or more efficient:
void foo(uint[] a) @nogc {
if (a.length == 2 && a[0] == 1 && a[1] == 2) {}
}
--
More information about the Digitalmars-d-bugs
mailing list