[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:50:13 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13381
--- Comment #5 from yebblies <yebblies at gmail.com> ---
(In reply to bearophile_hugs from comment #4)
> (In reply to yebblies from comment #3)
>
> > For this case, and similar cases, the compiler can simply type the array
> > literal as a static array, because it knows that == can't escape any
> > references. It already does something like this for indexing array literals.
>
> I see. I have suggested a rewrite like this:
>
> if (a.length == 2 && a[0] == 1 && a[1] == 2) {}
>
> Because most array literals used for equality or comparison are short or
> very short, so calling == or < on few single items is much more efficient
> than calling a runtime function that works on whole arrays.
Ideally the optimizer would do this by itself, once the literal is
stack-allocated. I suspect it already does in some cases for gdc/ldc.
--
More information about the Digitalmars-d-bugs
mailing list