summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst2
-rw-r--r--Python/ceval.c8
-rw-r--r--Python/specialize.c12
3 files changed, 10 insertions, 12 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst
new file mode 100644
index 0000000..f705b41
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst
@@ -0,0 +1,2 @@
+Remove an existing "fast path" for old-style string formatting, since
+it no longer appears to have any measurable impact.
diff --git a/Python/ceval.c b/Python/ceval.c
index 0b24cbd..e808aee 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4711,14 +4711,6 @@ check_eval_breaker:
res = PyNumber_Multiply(lhs, rhs);
break;
case NB_REMAINDER:
- if (PyUnicode_CheckExact(lhs) &&
- (!PyUnicode_Check(rhs) || PyUnicode_CheckExact(rhs)))
- {
- // bpo-28598: Fast path for string formatting (but not
- // if the RHS is a str subclass).
- res = PyUnicode_Format(lhs, rhs);
- break;
- }
res = PyNumber_Remainder(lhs, rhs);
break;
case NB_OR:
diff --git a/Python/specialize.c b/Python/specialize.c
index 7e72013..cfc21bf 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1380,13 +1380,13 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
SpecializedCacheEntry *cache)
{
_PyAdaptiveEntry *adaptive = &cache->adaptive;
- if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
- SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
- goto failure;
- }
switch (adaptive->original_oparg) {
case NB_ADD:
case NB_INPLACE_ADD:
+ if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
+ SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
+ goto failure;
+ }
if (PyUnicode_CheckExact(lhs)) {
if (_Py_OPCODE(instr[1]) == STORE_FAST && Py_REFCNT(lhs) == 2) {
*instr = _Py_MAKECODEUNIT(BINARY_OP_INPLACE_ADD_UNICODE,
@@ -1409,6 +1409,10 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
break;
case NB_MULTIPLY:
case NB_INPLACE_MULTIPLY:
+ if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
+ SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
+ goto failure;
+ }
if (PyLong_CheckExact(lhs)) {
*instr = _Py_MAKECODEUNIT(BINARY_OP_MULTIPLY_INT,
_Py_OPARG(*instr));