summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2024-10-28 21:37:16 (GMT)
committerGitHub <noreply@github.com>2024-10-28 21:37:16 (GMT)
commitb5b06349eb71b7cf9e5082e26e6fe0145875f95b (patch)
treed7d6405b8982683bf0df6885a4ad4f719507874c /Python/optimizer_bytecodes.c
parentdcda92f8fcfa70ef48935db0dc468734de897d96 (diff)
downloadcpython-b5b06349eb71b7cf9e5082e26e6fe0145875f95b.zip
cpython-b5b06349eb71b7cf9e5082e26e6fe0145875f95b.tar.gz
cpython-b5b06349eb71b7cf9e5082e26e6fe0145875f95b.tar.bz2
GH-125912: Teach the JIT's optimizer about _BINARY_OP_INPLACE_ADD_UNICODE (GH-125935)
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index d71b55c..f40ad1e 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -331,6 +331,24 @@ dummy_func(void) {
}
}
+ op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) {
+ _Py_UopsSymbol *res;
+ if (sym_is_const(left) && sym_is_const(right) &&
+ sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
+ PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
+ if (temp == NULL) {
+ goto error;
+ }
+ res = sym_new_const(ctx, temp);
+ Py_DECREF(temp);
+ }
+ else {
+ res = sym_new_type(ctx, &PyUnicode_Type);
+ }
+ // _STORE_FAST:
+ GETLOCAL(this_instr->operand) = res;
+ }
+
op(_BINARY_SUBSCR_INIT_CALL, (container, sub -- new_frame: _Py_UOpsAbstractFrame *)) {
(void)container;
(void)sub;