diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-06 19:07:53 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-06 19:07:53 (GMT) |
commit | ea525a2d1a798f529b015f86b174d478806ac7ec (patch) | |
tree | 4ed79494c2a6a8e3460027a246020d25c1eaca16 /Python/compile.c | |
parent | 620bb277f89ba373b8c50e1a9fb9c8ba77a245c4 (diff) | |
download | cpython-ea525a2d1a798f529b015f86b174d478806ac7ec.zip cpython-ea525a2d1a798f529b015f86b174d478806ac7ec.tar.gz cpython-ea525a2d1a798f529b015f86b174d478806ac7ec.tar.bz2 |
Issue #27078: Added BUILD_STRING opcode. Optimized f-strings evaluation.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/Python/compile.c b/Python/compile.c index fb80f51..b562989 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -970,6 +970,7 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg) case BUILD_TUPLE: case BUILD_LIST: case BUILD_SET: + case BUILD_STRING: return 1-oparg; case BUILD_LIST_UNPACK: case BUILD_TUPLE_UNPACK: @@ -3315,31 +3316,8 @@ compiler_call(struct compiler *c, expr_ty e) static int compiler_joined_str(struct compiler *c, expr_ty e) { - /* Concatenate parts of a string using ''.join(parts). There are - probably better ways of doing this. - - This is used for constructs like "'x=' f'{42}'", which have to - be evaluated at compile time. */ - - static PyObject *empty_string; - static PyObject *join_string; - - if (!empty_string) { - empty_string = PyUnicode_FromString(""); - if (!empty_string) - return 0; - } - if (!join_string) { - join_string = PyUnicode_FromString("join"); - if (!join_string) - return 0; - } - - ADDOP_O(c, LOAD_CONST, empty_string, consts); - ADDOP_NAME(c, LOAD_ATTR, join_string, names); VISIT_SEQ(c, expr, e->v.JoinedStr.values); - ADDOP_I(c, BUILD_LIST, asdl_seq_LEN(e->v.JoinedStr.values)); - ADDOP_I(c, CALL_FUNCTION, 1); + ADDOP_I(c, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values)); return 1; } |