buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Optimize list and map initialization

Open giann opened this issue 1 year ago • 0 comments

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.

giann avatar Jan 06 '24 14:01 giann