Skip to content

Commit 8d23dad

Browse files
committed
Apply feedback from code review
1 parent f0d2056 commit 8d23dad

File tree

1 file changed

+9
-70
lines changed

1 file changed

+9
-70
lines changed

Python/ceval.c

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ static PyObject * import_from(PyThreadState *, PyObject *, PyObject *);
9292
static int import_all_from(PyThreadState *, PyObject *, PyObject *);
9393
static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *);
9494
static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
95-
static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *,
96-
InterpreterFrame *, const _Py_CODEUNIT *);
9795
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
9896
static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
9997
static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int);
@@ -4706,13 +4704,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
47064704
res = PyNumber_Xor(lhs, rhs);
47074705
break;
47084706
case NB_INPLACE_ADD:
4709-
if (PyUnicode_CheckExact(lhs) && PyUnicode_CheckExact(rhs))
4710-
{
4711-
Py_INCREF(lhs); // unicode_concatenate steals lhs!
4712-
res = unicode_concatenate(tstate, lhs, rhs, frame,
4713-
next_instr);
4714-
break;
4715-
}
47164707
res = PyNumber_InPlaceAdd(lhs, rhs);
47174708
break;
47184709
case NB_INPLACE_AND:
@@ -4766,18 +4757,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
47664757
TARGET(BINARY_OP_ADAPTIVE) {
47674758
assert(cframe.use_tracing == 0);
47684759
SpecializedCacheEntry *cache = GET_CACHE();
4769-
if (cache->adaptive.counter) {
4760+
if (cache->adaptive.counter == 0) {
4761+
PyObject *lhs = SECOND();
4762+
PyObject *rhs = TOP();
4763+
next_instr--;
4764+
_Py_Specialize_BinaryOp(lhs, rhs, next_instr, cache);
4765+
DISPATCH();
4766+
}
4767+
else {
4768+
STAT_INC(BINARY_OP, deferred);
47704769
cache->adaptive.counter--;
47714770
oparg = cache->adaptive.original_oparg;
4772-
STAT_INC(BINARY_OP, deferred);
47734771
STAT_DEC(BINARY_OP, unquickened);
47744772
JUMP_TO_INSTRUCTION(BINARY_OP);
47754773
}
4776-
PyObject *lhs = SECOND();
4777-
PyObject *rhs = TOP();
4778-
next_instr--;
4779-
_Py_Specialize_BinaryOp(lhs, rhs, next_instr, cache);
4780-
DISPATCH();
47814774
}
47824775

47834776
TARGET(EXTENDED_ARG) {
@@ -6901,60 +6894,6 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop
69016894
}
69026895
}
69036896

6904-
static PyObject *
6905-
unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w,
6906-
InterpreterFrame *frame, const _Py_CODEUNIT *next_instr)
6907-
{
6908-
PyObject *res;
6909-
if (Py_REFCNT(v) == 2) {
6910-
/* In the common case, there are 2 references to the value
6911-
* stored in 'variable' when the += is performed: one on the
6912-
* value stack (in 'v') and one still stored in the
6913-
* 'variable'. We try to delete the variable now to reduce
6914-
* the refcnt to 1.
6915-
*/
6916-
int opcode, oparg;
6917-
NEXTOPARG();
6918-
next_instr++;
6919-
switch (opcode) {
6920-
case STORE_FAST:
6921-
{
6922-
if (GETLOCAL(oparg) == v)
6923-
SETLOCAL(oparg, NULL);
6924-
break;
6925-
}
6926-
case STORE_DEREF:
6927-
{
6928-
PyObject *c = _PyFrame_GetLocalsArray(frame)[oparg];
6929-
if (PyCell_GET(c) == v) {
6930-
PyCell_SET(c, NULL);
6931-
Py_DECREF(v);
6932-
}
6933-
break;
6934-
}
6935-
case STORE_NAME:
6936-
{
6937-
PyObject *names = frame->f_code->co_names;
6938-
PyObject *name = GETITEM(names, oparg);
6939-
PyObject *locals = frame->f_locals;
6940-
if (locals && PyDict_CheckExact(locals)) {
6941-
PyObject *w = PyDict_GetItemWithError(locals, name);
6942-
if ((w == v && PyDict_DelItem(locals, name) != 0) ||
6943-
(w == NULL && _PyErr_Occurred(tstate)))
6944-
{
6945-
Py_DECREF(v);
6946-
return NULL;
6947-
}
6948-
}
6949-
break;
6950-
}
6951-
}
6952-
}
6953-
res = v;
6954-
PyUnicode_Append(&res, w);
6955-
return res;
6956-
}
6957-
69586897
#ifdef DYNAMIC_EXECUTION_PROFILE
69596898

69606899
static PyObject *

0 commit comments

Comments
 (0)