diff --git a/Python/compile.c b/Python/compile.c index 687b750..dd49514 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3323,23 +3323,32 @@ compiler_joined_str(struct compiler *c, expr_ty e) static PyObject *empty_string; static PyObject *join_string; + Py_ssize_t len; - 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; - } + len = asdl_seq_LEN(e->v.JoinedStr.values); + if (len > 2) { + 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); + 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); + if (len > 2) { + ADDOP_I(c, BUILD_TUPLE, len); + ADDOP_I(c, CALL_FUNCTION, 1); + } + else { + ADDOP(c, BINARY_ADD); + } return 1; }