Re: Dynamic array initialization syntax

2011-02-16 Thread Andrej Mitrovic
Oh, but there's a call to array. I guess that could slow things down, sorry.


Re: Dynamic array initialization syntax

2011-02-16 Thread Andrej Mitrovic
import std.stdio;
import std.range;

auto newArray(T)(T value, size_t size)
{
return array(take(repeat(value), size));
}

void main()
{
auto a1 = newArray(5, 3);
assert(a1 == [5, 5, 5]);
}


__Dmain:; Function begin, communal
sub esp, 28 ;  _ 83. EC, 1C
mov dword [esp+8H], 5   ; 0003 _ C7.
44 24, 08, 0005
mov dword [esp+4H], 1   ; 000B _ C7.
44 24, 04, 0001
mov edx, dword [esp+8H] ; 0013 _ 8B. 54 24, 08
mov eax, dword [esp+4H] ; 0017 _ 8B. 44 24, 04
pushedx ; 001B _ 52
pusheax ; 001C _ 50
call
_D3std5array72__T̔Sزange43״TakeֱֶRepeatTiZ˚ɚƆ>Ɓi; 001D _ E8,
(rel)
add esp, 28 ; 0022 _ 83. C4, 1C
xor eax, eax; 0025 _ 31. C0
ret ; 0027 _ C3
; __Dmain End of function

Is that good? I can't tell, I'm still working my way around the asm book. :)

But you did say there's an extra __memset32 call in your #2 example in
the bug issue report, and I don't see one here.


Dynamic array initialization syntax

2011-02-16 Thread bearophile
I have suggested a simple initialization syntax for dynamic arrays, similar to 
the syntax used for fixed-sized arrays:
http://d.puremagic.com/issues/show_bug.cgi?id=5603

void main() {
auto a2 = new int[5] = void;
auto a1 = new int[5] = 1;
auto m2 = new int[][](5, 5) = void;
auto m1 = new int[][](5, 5) = 1;
}

Surely I am not the first person to suggest this :-)

Bye,
bearophile