[Issue 2356] array literal as non static initializer generates horribly inefficient code.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 30 07:17:41 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=2356


Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg at gmail.com


--- Comment #13 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-10-30 17:17:29 MSK ---
Workaround for those who like "a, b, c" initialization but need more
performance (not: it still calls `_d_arraycopy`):

---
T[n] makeStaticArray(T, size_t n)(T[n] data...)
// { return data; }
{ T[n] res; res = data; return res; } // Issue 8914 workaround

void setStaticArray(T, size_t n)(ref T[n] array, T[n] data...)
{ array = data; }

void main()
{
    auto x = makeStaticArray(1, 2, 3);
    static assert(is(typeof(x) == int[3]));
    assert(x == [1, 2, 3]);

    int[3] y;
    y.setStaticArray(1, 2, 3);
    assert(y == [1, 2, 3]);
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list