haxetink / tink_pure

Pure immutable data.
MIT License
10 stars 7 forks source link

Initialize vector from array comprehension #19

Closed kevinresol closed 3 years ago

kevinresol commented 3 years ago

Currently array comprehension will invoke ofArray does a .copy() call, which is unnecessary

var a:Vector<Int> = [for(i in 0...2) i];

generates:

var _g = [];
_g.push(0);
_g.push(1);
var this1 = _g.slice();

I guess the reason is that typeExpr will convert a EArrayDecl into some "init+push" instructions does breaking the switch. I wonder why if we can't just rely on EArrayDecl instead of TArrayDecl in the first case?

https://github.com/haxetink/tink_pure/blob/f93e378516aeda3b31487c09f46300714b86a49a/src/tink/pure/Vector.hx#L84-L85

kevinresol commented 3 years ago

Hmm apparently the argument provided to ofAny is a @:this this expression