Skip to content

Conversation

pitrou
Copy link
Member

@pitrou pitrou commented Dec 19, 2017

@@ -1979,7 +2006,6 @@ mro_internal(PyTypeObject *type, PyObject **p_old_mro)
return 1;
}


Copy link
Member

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);
Copy link
Member

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?

Copy link
Member Author

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.

return mro_implementation(self);
PyObject *seq;
seq = mro_implementation(self);
if (seq != NULL && PyTuple_CheckExact(seq)) {
Copy link
Member

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().

PyObject *seq;
seq = mro_implementation(self);
if (seq != NULL && PyTuple_CheckExact(seq)) {
PyObject *lst = PySequence_List(seq);
Copy link
Member

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.

Copy link
Member Author

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 :-)

@pitrou pitrou merged commit 1f1a34c into python:master Dec 20, 2017
@pitrou pitrou deleted the faster_mro_impl branch December 20, 2017 14:58
@pitrou
Copy link
Member Author

pitrou commented Dec 20, 2017

Thanks for the review @serhiy-storchaka !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants