-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
bpo-32379: Faster MRO computation for single inheritance #4932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Objects/typeobject.c
Outdated
@@ -1979,7 +2006,6 @@ mro_internal(PyTypeObject *type, PyObject **p_old_mro) | |||
return 1; | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change.
return NULL; | ||
} | ||
k = PyTuple_GET_SIZE(base->tp_mro); | ||
result = PyTuple_New(k + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the result be a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a list? The caller calls PySequence_Tuple
on the result, so it's faster if we create a tuple upfront.
Objects/typeobject.c
Outdated
return mro_implementation(self); | ||
PyObject *seq; | ||
seq = mro_implementation(self); | ||
if (seq != NULL && PyTuple_CheckExact(seq)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write !PyList_Check()
.
Objects/typeobject.c
Outdated
PyObject *seq; | ||
seq = mro_implementation(self); | ||
if (seq != NULL && PyTuple_CheckExact(seq)) { | ||
PyObject *lst = PySequence_List(seq); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may look clearer with
Py_SETREF(seq, PySequence_List(seq));
and a single return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to get used to it :-)
Thanks for the review @serhiy-storchaka ! |
https://bugs.python.org/issue32379