summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-09-13 17:25:45 (GMT)
committerGitHub <noreply@github.com>2023-09-13 17:25:45 (GMT)
commit22e65eecaad3f5337862319687047afe9861e1ef (patch)
tree19089993cd9ec4d1930521c1c3df3cb22b0b9ddc /Python/compile.c
parent987b4bc0870e1e29a88275dc3fa39bf2c3dcc763 (diff)
downloadcpython-22e65eecaad3f5337862319687047afe9861e1ef.zip
cpython-22e65eecaad3f5337862319687047afe9861e1ef.tar.gz
cpython-22e65eecaad3f5337862319687047afe9861e1ef.tar.bz2
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 1f08e46..b05c1ad 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4982,9 +4982,13 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
VISIT_SEQ(c, keyword, kwds);
RETURN_IF_ERROR(
compiler_call_simple_kw_helper(c, loc, kwds, kwdsl));
+ loc = update_start_location_to_match_attr(c, LOC(e), meth);
+ ADDOP_I(c, loc, CALL_KW, argsl + kwdsl);
+ }
+ else {
+ loc = update_start_location_to_match_attr(c, LOC(e), meth);
+ ADDOP_I(c, loc, CALL, argsl);
}
- loc = update_start_location_to_match_attr(c, LOC(e), meth);
- ADDOP_I(c, loc, CALL, argsl + kwdsl);
return 1;
}
@@ -5150,7 +5154,7 @@ compiler_subkwargs(struct compiler *c, location loc,
}
/* Used by compiler_call_helper and maybe_optimize_method_call to emit
- * KW_NAMES before CALL.
+ * a tuple of keyword names before CALL.
*/
static int
compiler_call_simple_kw_helper(struct compiler *c, location loc,
@@ -5165,12 +5169,7 @@ compiler_call_simple_kw_helper(struct compiler *c, location loc,
keyword_ty kw = asdl_seq_GET(keywords, i);
PyTuple_SET_ITEM(names, i, Py_NewRef(kw->arg));
}
- Py_ssize_t arg = compiler_add_const(c->c_const_cache, c->u, names);
- if (arg < 0) {
- return ERROR;
- }
- Py_DECREF(names);
- ADDOP_I(c, loc, KW_NAMES, arg);
+ ADDOP_LOAD_CONST_NEW(c, loc, names);
return SUCCESS;
}
@@ -5215,8 +5214,11 @@ compiler_call_helper(struct compiler *c, location loc,
VISIT_SEQ(c, keyword, keywords);
RETURN_IF_ERROR(
compiler_call_simple_kw_helper(c, loc, keywords, nkwelts));
+ ADDOP_I(c, loc, CALL_KW, n + nelts + nkwelts);
+ }
+ else {
+ ADDOP_I(c, loc, CALL, n + nelts);
}
- ADDOP_I(c, loc, CALL, n + nelts + nkwelts);
return SUCCESS;
ex_call: