Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0a865c9
Speed up type creation, which is highly dominated by slow dict lookups.
Sep 4, 2017
c4779e3
Update comment after changing the function call that it refers to.
Sep 4, 2017
ff2ea63
Ignore any errors (however unlikely) that may happen during the mro c…
Sep 4, 2017
76b1986
Extract non-caching code from _PyType_Lookup() to use it directly fro…
Sep 5, 2017
6f98485
Avoid some useless overhead for the no-basetype case. If "object" eve…
Sep 5, 2017
d9b726e
Add comment.
Sep 6, 2017
be15255
Avoid uselessly searching empty bases for a metaclass. This is quite …
Sep 6, 2017
0736226
Avoid unsafe handling of borrowed "mro" reference during hash() call.
Sep 10, 2017
8bc783f
Clean up code and formatting a little.
Sep 10, 2017
66648dd
Add braces for code style reasons.
Sep 10, 2017
85fb3ae
Give internal helper function a local name that does not resemble (ex…
Sep 10, 2017
09e716a
Allow non-dict types for the class dict when looking up names and cal…
Sep 11, 2017
1d52082
Lazily calculate name hash in find_name_in_mro() to avoid potential r…
Sep 11, 2017
f09bfd3
Revert "Lazily calculate name hash in find_name_in_mro() to avoid pot…
Sep 11, 2017
824d7cb
Revert "Allow non-dict types for the class dict when looking up names…
Sep 11, 2017
5184191
add news entry for faster class creation
Sep 13, 2017
4efde8e
Change nice interface of "find_name_in_mro()" to evil interface eatin…
Sep 13, 2017
f5bce2a
Mention amount of speedup in News entry.
Sep 13, 2017
02bfef0
Revert "Change nice interface of "find_name_in_mro()" to evil interfa…
Sep 14, 2017
2497858
Guard against external live exceptions when calling find_name_in_mro(…
Sep 14, 2017
c56990d
Merge branch 'master' into _pt_lookup_exc
Sep 15, 2017
6c61028
Propagate exception when _PyObject_LookupSpecial() fails (as done eve…
Sep 14, 2017
1b5950f
Allow _PyType_Lookup() and _PyType_LookupId() to raise exceptions and…
Sep 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid uselessly searching empty bases for a metaclass. This is quite …
…common in Python 3 now.

Also make the step from "return NULL" error handling to "goto error" reference cleanup explicit.
  • Loading branch information
Stefan Behnel
Stefan Behnel committed Sep 6, 2017
commit be15255ff763ce1018a7318590dc37a4c1e04a00
32 changes: 17 additions & 15 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2360,37 +2360,39 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
&bases, &PyDict_Type, &orig_dict))
return NULL;

/* Determine the proper metatype to deal with this: */
winner = _PyType_CalculateMetaclass(metatype, bases);
if (winner == NULL) {
return NULL;
}

if (winner != metatype) {
if (winner->tp_new != type_new) /* Pass it to the winner */
return winner->tp_new(winner, args, kwds);
metatype = winner;
}

/* Adjust for empty tuple bases */
nbases = PyTuple_GET_SIZE(bases);
if (nbases == 0) {
base = &PyBaseObject_Type;
bases = PyTuple_Pack(1, base);
if (bases == NULL)
goto error;
return NULL;
nbases = 1;
}
else {
Py_INCREF(bases);
/* Search the bases for the proper metatype to deal with this: */
winner = _PyType_CalculateMetaclass(metatype, bases);
if (winner == NULL) {
return NULL;
}

if (winner != metatype) {
if (winner->tp_new != type_new) /* Pass it to the winner */
return winner->tp_new(winner, args, kwds);
metatype = winner;
}

/* Calculate best base, and check that all bases are type objects */
base = best_base(bases);
if (base == NULL) {
goto error;
return NULL;
}

Py_INCREF(bases);
}

/* Use "goto error" from this point on as we now own the reference to "bases". */

dict = PyDict_Copy(orig_dict);
if (dict == NULL)
goto error;
Expand Down