https://issues.dlang.org/show_bug.cgi?id=13381
--- Comment #5 from yebblies <yebbl...@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. --