buzz
buzz copied to clipboard
Optimize list and map initialization
Instead of:
000 041 OP_LIST 7 type: 0x101617c00 `[int]`
001 | OP_CONSTANT 1 10
002 | OP_LIST_APPEND
003 | OP_CONSTANT 2 3
004 | OP_LIST_APPEND
005 | OP_CONSTANT 3 12
006 | OP_LIST_APPEND
007 | OP_CONSTANT 4 0
Do:
000 041 OP_LIST 7 type: 0x101617c00 `[int]`
001 | OP_CONSTANT 1 10
002 | OP_CONSTANT 2 3
003 | OP_CONSTANT 3 12
004 | OP_CONSTANT 4 0
005 | OP_LIST_APPEND 4 // There's 4 elements on the stack to append to the list
This is also true with maps.