dev_compiler icon indicating copy to clipboard operation
dev_compiler copied to clipboard

Improved dart.list and dart.map

Open rakudrama opened this issue 9 years ago • 1 comments

dart.list takes an element type. We should investigate using a factory constructor instead.

The problem is that

dart.list([1, 2, 3], core.int)

must to look up the type JSArray<core.int> each time. We could generate a call to a factory constructor, e.g. named _of,

core.List$(core.int)._of([1, 2, 3])

This would still create the parameterized type, but we can then apply other improvements to the core.List$(core.int) part, e.g. precomputing it or caching it.

List<E>._of(array) could be defined in the patch file. It could simply call JSArray<E>.typed(array) (we would want to fix #561 to make that faster). Or List<E>._of could have a precomputed type JSArray<E> available to immediately store on the array.

Something similar could be done with dart.map to enable types to be evaluated less often.

rakudrama avatar May 17 '16 01:05 rakudrama

List case has been implemented in https://github.com/dart-lang/dev_compiler/commit/b2ebb32cbdf4ac4c35c537e7711ced5d54b04f1b

dart.list([1, 2, 3], core.int)

is now

JSArrayOfint().of([1, 2, 3])

where JSArrayOfint() is the cached evaluation of _interceptors.JSArray$(core.int)

Map case is still TODO

rakudrama avatar Jun 02 '16 21:06 rakudrama