8000 Teach the optimizer about _BINARY_OP_INPLACE_ADD_UNICODE · python/cpython@f4d6b30 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4d6b30

Browse files
committed
Teach the optimizer about _BINARY_OP_INPLACE_ADD_UNICODE
1 parent 34653bb commit f4d6b30

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Python/optimizer_bytecodes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ dummy_func(void) {
331331
}
332332
}
333333

334+
op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) {
335+
_Py_UopsSymbol *res;
336+
if (sym_is_const(left) && sym_is_const(right) &&
337+
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
338+
PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
339+
if (temp == NULL) {
340+
goto error;
341+
}
342+
res = sym_new_const(ctx, temp);
343+
Py_DECREF(temp);
344+
}
345+
else {
346+
res = sym_new_type(ctx, &PyUnicode_Type);
347+
}
348+
// _STORE_FAST:
349+
GETLOCAL(this_instr->operand) = res;
350+
}
351+
334352
op(_BINARY_SUBSCR_INIT_CALL, (container, sub -- new_frame: _Py_UOpsAbstractFrame *)) {
335353
(void)container;
336354
(void)sub;

Python/optimizer_cases.c.h

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0