[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:42:32 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13381

--- Comment #4 from bearophile_hugs at eml.cc ---
(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.

--


More information about the Digitalmars-d-bugs mailing list