summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-03-21 07:47:15 (GMT)
committerGitHub <noreply@github.com>2023-03-21 07:47:15 (GMT)
commit82eb9469e717e0047543732287a8342e646c2262 (patch)
tree4a1f46cc83ceea4efaa60a9ae73c2361c165da0a /Python
parent1a5a14183ec807ead1c6a46464540159124e5260 (diff)
downloadcpython-82eb9469e717e0047543732287a8342e646c2262.zip
cpython-82eb9469e717e0047543732287a8342e646c2262.tar.gz
cpython-82eb9469e717e0047543732287a8342e646c2262.tar.bz2
gh-102598: Remove obsolete optimization from `FORMAT_VALUE` opcode (#102599)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c18
-rw-r--r--Python/generated_cases.c.h47
2 files changed, 21 insertions, 44 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 6c44870..ce2a58b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -3026,20 +3026,10 @@ dummy_func(
value = result;
}
- /* If value is a unicode object, and there's no fmt_spec,
- then we know the result of format(value) is value
- itself. In that case, skip calling format(). I plan to
- move this optimization in to PyObject_Format()
- itself. */
- if (PyUnicode_CheckExact(value) && fmt_spec == NULL) {
- /* Do nothing, just transfer ownership to result. */
- result = value;
- } else {
- /* Actually call format(). */
- result = PyObject_Format(value, fmt_spec);
- DECREF_INPUTS();
- ERROR_IF(result == NULL, error);
- }
+ result = PyObject_Format(value, fmt_spec);
+ Py_DECREF(value);
+ Py_XDECREF(fmt_spec);
+ ERROR_IF(result == NULL, error);
}
inst(COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index c5a7d90..34b608f 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -4252,24 +4252,11 @@
value = result;
}
- /* If value is a unicode object, and there's no fmt_spec,
- then we know the result of format(value) is value
- itself. In that case, skip calling format(). I plan to
- move this optimization in to PyObject_Format()
- itself. */
- if (PyUnicode_CheckExact(value) && fmt_spec == NULL) {
- /* Do nothing, just transfer ownership to result. */
- result = value;
- } else {
- /* Actually call format(). */
- result = PyObject_Format(value, fmt_spec);
- #line 4267 "Python/generated_cases.c.h"
- Py_DECREF(value);
- Py_XDECREF(fmt_spec);
- #line 3041 "Python/bytecodes.c"
- if (result == NULL) { STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); goto pop_1_error; }
- }
- #line 4273 "Python/generated_cases.c.h"
+ result = PyObject_Format(value, fmt_spec);
+ Py_DECREF(value);
+ Py_XDECREF(fmt_spec);
+ if (result == NULL) { STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); goto pop_1_error; }
+ #line 4260 "Python/generated_cases.c.h"
STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0));
stack_pointer[-1] = result;
DISPATCH();
@@ -4278,10 +4265,10 @@
TARGET(COPY) {
PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
PyObject *top;
- #line 3046 "Python/bytecodes.c"
+ #line 3036 "Python/bytecodes.c"
assert(oparg > 0);
top = Py_NewRef(bottom);
- #line 4285 "Python/generated_cases.c.h"
+ #line 4272 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = top;
DISPATCH();
@@ -4293,7 +4280,7 @@
PyObject *rhs = stack_pointer[-1];
PyObject *lhs = stack_pointer[-2];
PyObject *res;
- #line 3051 "Python/bytecodes.c"
+ #line 3041 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -4309,12 +4296,12 @@
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
res = binary_ops[oparg](lhs, rhs);
- #line 4313 "Python/generated_cases.c.h"
+ #line 4300 "Python/generated_cases.c.h"
Py_DECREF(lhs);
Py_DECREF(rhs);
- #line 3067 "Python/bytecodes.c"
+ #line 3057 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
- #line 4318 "Python/generated_cases.c.h"
+ #line 4305 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 1;
@@ -4324,27 +4311,27 @@
TARGET(SWAP) {
PyObject *top = stack_pointer[-1];
PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
- #line 3072 "Python/bytecodes.c"
+ #line 3062 "Python/bytecodes.c"
assert(oparg >= 2);
- #line 4330 "Python/generated_cases.c.h"
+ #line 4317 "Python/generated_cases.c.h"
stack_pointer[-1] = bottom;
stack_pointer[-(2 + (oparg-2))] = top;
DISPATCH();
}
TARGET(EXTENDED_ARG) {
- #line 3076 "Python/bytecodes.c"
+ #line 3066 "Python/bytecodes.c"
assert(oparg);
assert(cframe.use_tracing == 0);
opcode = next_instr->op.code;
oparg = oparg << 8 | next_instr->op.arg;
PRE_DISPATCH_GOTO();
DISPATCH_GOTO();
- #line 4344 "Python/generated_cases.c.h"
+ #line 4331 "Python/generated_cases.c.h"
}
TARGET(CACHE) {
- #line 3085 "Python/bytecodes.c"
+ #line 3075 "Python/bytecodes.c"
Py_UNREACHABLE();
- #line 4350 "Python/generated_cases.c.h"
+ #line 4337 "Python/generated_cases.c.h"
}