Skip to content

Commit 8f21380

Browse files
committed
Clean things up a bit
1 parent c5d6922 commit 8f21380

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

Python/ceval.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,12 +4564,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
45644564
We'll be passing `oparg + 1` to call_function, to
45654565
make it accept the `self` as a first argument.
45664566
*/
4567-
int is_method = (PEEK(oparg + 2) != NULL);
4568-
int nargs = oparg + is_method;
4567+
int is_meth = is_method(stack_pointer, oparg);
4568+
int nargs = oparg + is_meth;
45694569
/* Move ownership of reference from stack to call_shape
45704570
* and make sure that NULL is cleared from stack */
45714571
PyObject *function = PEEK(nargs + 1);
4572-
if (!is_method && Py_TYPE(function) == &PyMethod_Type) {
4572+
if (!is_meth && Py_TYPE(function) == &PyMethod_Type) {
45734573
PyObject *meth = ((PyMethodObject *)function)->im_func;
45744574
PyObject *self = ((PyMethodObject *)function)->im_self;
45754575
Py_INCREF(meth);
@@ -4583,8 +4583,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
45834583
}
45844584

45854585
TARGET(PRECALL_BOUND_METHOD) {
4586-
int is_method = (PEEK(oparg + 2) != NULL);
4587-
DEOPT_IF(is_method, PRECALL);
4586+
DEOPT_IF(is_method(stack_pointer, oparg), PRECALL);
45884587
PyObject *function = PEEK(oparg + 1);
45894588
DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, PRECALL);
45904589
STAT_INC(PRECALL, hit);
@@ -4600,8 +4599,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
46004599
}
46014600

46024601
TARGET(PRECALL_PYFUNC) {
4603-
int is_method = (PEEK(oparg + 2) != NULL);
4604-
int nargs = oparg + is_method;
4602+
int nargs = oparg + is_method(stack_pointer, oparg);
46054603
PyObject *function = PEEK(nargs + 1);
46064604
DEOPT_IF(Py_TYPE(function) != &PyFunction_Type, PRECALL);
46074605
STAT_INC(PRECALL, hit);

Python/specialize.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ optimize(_Py_CODEUNIT *instructions, int len)
311311
else {
312312
assert(!_PyOpcode_InlineCacheEntries[opcode]);
313313
switch (opcode) {
314-
case JUMP_ABSOLUTE:
314+
case JUMP_ABSOLUTE:
315315
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
316316
break;
317317
case RESUME:
@@ -1475,10 +1475,6 @@ builtin_call_fail_kind(int ml_flags)
14751475
}
14761476
#endif
14771477

1478-
PyObject *builtin_isinstance = NULL;
1479-
PyObject *builtin_len = NULL;
1480-
PyObject *builtin_list_append = NULL;
1481-
14821478
static int
14831479
specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
14841480
int nargs, PyObject *kwnames, int oparg)
@@ -1488,14 +1484,6 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
14881484
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_KWNAMES);
14891485
return -1;
14901486
}
1491-
if (builtin_list_append == NULL) {
1492-
builtin_list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
1493-
}
1494-
assert(builtin_list_append != NULL);
1495-
if (nargs == 2 && (PyObject *)descr == builtin_list_append && oparg == 1) {
1496-
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_LIST_APPEND, _Py_OPARG(*instr));
1497-
return 0;
1498-
}
14991487

15001488
switch (descr->d_method->ml_flags &
15011489
(METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
@@ -1511,9 +1499,16 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
15111499
}
15121500
case METH_O: {
15131501
if (nargs != 2) {
1514-
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_OUT_OF_RANGE);
1502+
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
15151503
return -1;
15161504
}
1505+
PyInterpreterState *interp = _PyInterpreterState_GET();
1506+
PyObject *list_append = interp->callable_cache.list_append;
1507+
if ((PyObject *)descr == list_append && oparg == 1) {
1508+
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_LIST_APPEND,
1509+
_Py_OPARG(*instr));
1510+
return 0;
1511+
}
15171512
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_METHOD_DESCRIPTOR_O,
15181513
_Py_OPARG(*instr));
15191514
return 0;
@@ -1705,7 +1700,7 @@ _Py_Specialize_Precall(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
17051700
fail = 0;
17061701
}
17071702
else {
1708-
SPECIALIZATION_FAIL(CALL, call_fail_kind(callable));
1703+
SPECIALIZATION_FAIL(PRECALL, call_fail_kind(callable));
17091704
fail = -1;
17101705
}
17111706
if (fail) {

0 commit comments

Comments
 (0)