Serhiy Storchaka added the comment:
Proposed patch adds the BUILD_MAP_EX opcode (maybe somebody propose better
name?). It takes values from the stack and keys from the tuple on the top of
the stack. Currently it affects only creating a dict with const keys and
calling a function with keywords after the var-keyword argument.
$ echo "{'a': 1, 'b': 2, 'c': 3}" | ./python -m dis
Unpatched:
1 0 LOAD_CONST 0 ('a')
2 LOAD_CONST 1 (1)
4 LOAD_CONST 2 ('b')
6 LOAD_CONST 3 (2)
8 LOAD_CONST 4 ('c')
10 LOAD_CONST 5 (3)
12 BUILD_MAP 3
14 POP_TOP
16 LOAD_CONST 6 (None)
18 RETURN_VALUE
Patched:
1 0 LOAD_CONST 0 (1)
2 LOAD_CONST 1 (2)
4 LOAD_CONST 2 (3)
6 LOAD_CONST 7 (('a', 'b', 'c'))
8 BUILD_MAP_EX 3
10 POP_TOP
12 LOAD_CONST 6 (None)
14 RETURN_VALUE
$ echo "f(**kw, a=1, b=2, c=3)" | ./python -m dis
Unpatched:
1 0 LOAD_NAME 0 (f)
2 LOAD_NAME 1 (kw)
4 LOAD_CONST 0 ('a')
6 LOAD_CONST 1 (1)
8 LOAD_CONST 2 ('b')
10 LOAD_CONST 3 (2)
12 LOAD_CONST 4 ('c')
14 LOAD_CONST 5 (3)
16 BUILD_MAP 3
18 EXTENDED_ARG 1
20 BUILD_MAP_UNPACK_WITH_CALL 258
22 CALL_FUNCTION_KW 0 (0 positional, 0 keyword pair)
24 POP_TOP
26 LOAD_CONST 6 (None)
28 RETURN_VALUE
Patched:
1 0 LOAD_NAME 0 (f)
2 LOAD_NAME 1 (kw)
4 LOAD_CONST 0 (1)
6 LOAD_CONST 1 (2)
8 LOAD_CONST 2 (3)
10 LOAD_CONST 7 (('a', 'b', 'c'))
12 BUILD_MAP_EX 3
14 EXTENDED_ARG 1
16 BUILD_MAP_UNPACK_WITH_CALL 258
18 CALL_FUNCTION_KW 0 (0 positional, 0 keyword pair)
20 POP_TOP
22 LOAD_CONST 6 (None)
24 RETURN_VALUE
It could be more useful for new MAKE_FUNCTION opcode (issue27095) and maybe for
new CALL_FUNCTION* opcodes.
The benefit of BUILD_MAP_EX is less LOAD_CONST instructions and less stack
consuming.
----------
keywords: +patch
nosy: +benjamin.peterson, brett.cannon, georg.brandl, ncoghlan, yselivanov
stage: needs patch -> patch review
Added file: http://bugs.python.org/file43055/BUILD_MAP_EX.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue27140>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com