Skip to content

Commit ec382fa

Browse files
authored
bpo-45636: Remove the old %-formatting fast-path (GH-29532)
1 parent 822c3dc commit ec382fa

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove an existing "fast path" for old-style string formatting, since
2+
it no longer appears to have any measurable impact.

Diff for: Python/ceval.c

-8
Original file line numberDiff line numberDiff line change
@@ -4711,14 +4711,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
47114711
res = PyNumber_Multiply(lhs, rhs);
47124712
break;
47134713
case NB_REMAINDER:
4714-
if (PyUnicode_CheckExact(lhs) &&
4715-
(!PyUnicode_Check(rhs) || PyUnicode_CheckExact(rhs)))
4716-
{
4717-
// bpo-28598: Fast path for string formatting (but not
4718-
// if the RHS is a str subclass).
4719-
res = PyUnicode_Format(lhs, rhs);
4720-
break;
4721-
}
47224714
res = PyNumber_Remainder(lhs, rhs);
47234715
break;
47244716
case NB_OR:

Diff for: Python/specialize.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -1380,13 +1380,13 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
13801380
SpecializedCacheEntry *cache)
13811381
{
13821382
_PyAdaptiveEntry *adaptive = &cache->adaptive;
1383-
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
1384-
SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
1385-
goto failure;
1386-
}
13871383
switch (adaptive->original_oparg) {
13881384
case NB_ADD:
13891385
case NB_INPLACE_ADD:
1386+
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
1387+
SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
1388+
goto failure;
1389+
}
13901390
if (PyUnicode_CheckExact(lhs)) {
13911391
if (_Py_OPCODE(instr[1]) == STORE_FAST && Py_REFCNT(lhs) == 2) {
13921392
*instr = _Py_MAKECODEUNIT(BINARY_OP_INPLACE_ADD_UNICODE,
@@ -1409,6 +1409,10 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
14091409
break;
14101410
case NB_MULTIPLY:
14111411
case NB_INPLACE_MULTIPLY:
1412+
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
1413+
SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
1414+
goto failure;
1415+
}
14121416
if (PyLong_CheckExact(lhs)) {
14131417
*instr = _Py_MAKECODEUNIT(BINARY_OP_MULTIPLY_INT,
14141418
_Py_OPARG(*instr));

0 commit comments

Comments
 (0)