Skip to content

Commit b468647

Browse files
committed
Code review
1 parent 5281c71 commit b468647

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Improve :opcode:`MATCH_CLASS` performance. Patch by Marc Mueller
1+
Improve :opcode:`MATCH_CLASS` performance by up to 52% in certain cases. Patch by Marc Mueller.

Python/ceval.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,9 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
745745
}
746746
// Short circuit if there aren't any arguments:
747747
Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwargs);
748-
Py_ssize_clean_t nattrs = nargs + nkwargs;
748+
Py_ssize_t nattrs = nargs + nkwargs;
749749
if (!nattrs) {
750-
PyObject *attrs = PyTuple_New(0);
751-
return attrs;
750+
return PyTuple_New(0);
752751
}
753752
// So far so good:
754753
PyObject *seen = NULL;
@@ -803,7 +802,8 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
803802
}
804803
if (match_self) {
805804
// Easy. Copy the subject itself, and move on to kwargs.
806-
Py_INCREF(subject);
805+
Py_NewRef(subject);
806+
assert(PyTuple_GET_ITEM(attrs, 0) == NULL);
807807
PyTuple_SET_ITEM(attrs, 0, subject);
808808
}
809809
else {
@@ -820,6 +820,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
820820
if (attr == NULL) {
821821
goto fail;
822822
}
823+
assert(PyTuple_GET_ITEM(attrs, i) == NULL);
823824
PyTuple_SET_ITEM(attrs, i, attr);
824825
}
825826
}
@@ -832,6 +833,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
832833
if (attr == NULL) {
833834
goto fail;
834835
}
836+
assert(PyTuple_GET_ITEM(attrs, nargs + i) == NULL);
835837
PyTuple_SET_ITEM(attrs, nargs + i, attr);
836838
}
837839
Py_XDECREF(seen);

0 commit comments

Comments
 (0)