We can implement List.filled (_List.filled, _GrowableList.filled) more efficiently, without a loop which initializes array elements after creating a list - it can reuse initialization performed during array object allocation. For this purpose, we need the following:
Implement specialized array allocator stub which would take fill argument and use it to initialize array elements instead of null.
Add CreateFilledArray IL instruction (or modify CreateArray instruction to optionally take extra argument), and generate it using the stub. We might also need to generate inline allocation code to be on par with CreateArray.
Implement List.filled (and probably _List.filled, _GrowableList.filled) as recognized function in the VM and generate flow graph using the new instruction.
You could delete the old instruction afterward. Legacy mode List(n) would then be lowered to _List.filled with an explicit null. Then you should have approximately the same amount of code to maintain.
We can implement
List.filled
(_List.filled
,_GrowableList.filled
) more efficiently, without a loop which initializes array elements after creating a list - it can reuse initialization performed during array object allocation. For this purpose, we need the following:fill
argument and use it to initialize array elements instead ofnull
.CreateFilledArray
IL instruction (or modifyCreateArray
instruction to optionally take extra argument), and generate it using the stub. We might also need to generate inline allocation code to be on par withCreateArray
.List.filled
(and probably_List.filled
,_GrowableList.filled
) as recognized function in the VM and generate flow graph using the new instruction.