diff options
author | Mark Shannon <mark@hotpy.org> | 2023-06-22 08:48:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 08:48:19 (GMT) |
commit | 04492cbc9aa45ac2c12d22083c406a0364c39f5b (patch) | |
tree | 4eb26dc0dca29519cabe1086aec523bc29e8f4b5 /Objects | |
parent | c01da2896ab92ba7193bcd6ae56908c5c7277e75 (diff) | |
download | cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.zip cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.tar.gz cpython-04492cbc9aa45ac2c12d22083c406a0364c39f5b.tar.bz2 |
GH-91095: Specialize calls to normal Python classes. (GH-99331)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 7 | ||||
-rw-r--r-- | Objects/typeobject.c | 20 |
2 files changed, 23 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 254cd9a..194081d 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -5334,11 +5334,10 @@ _PyDict_NewKeysForClass(void) #define CACHED_KEYS(tp) (((PyHeapTypeObject*)tp)->ht_cached_keys) -static int -init_inline_values(PyObject *obj, PyTypeObject *tp) +int +_PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp) { assert(tp->tp_flags & Py_TPFLAGS_HEAPTYPE); - // assert(type->tp_dictoffset > 0); -- TO DO Update this assert. assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT); PyDictKeysObject *keys = CACHED_KEYS(tp); assert(keys != NULL); @@ -5370,7 +5369,7 @@ _PyObject_InitializeDict(PyObject *obj) } if (tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) { OBJECT_STAT_INC(new_values); - return init_inline_values(obj, tp); + return _PyObject_InitInlineValues(obj, tp); } PyObject *dict; if (_PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE) && CACHED_KEYS(tp)) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index cbba6f0..d427ecd 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1682,6 +1682,26 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) } PyObject * +_PyType_NewManagedObject(PyTypeObject *type) +{ + assert(type->tp_flags & Py_TPFLAGS_MANAGED_DICT); + assert(_PyType_IS_GC(type)); + assert(type->tp_new == PyBaseObject_Type.tp_new); + assert(type->tp_alloc == PyType_GenericAlloc); + assert(type->tp_itemsize == 0); + PyObject *obj = PyType_GenericAlloc(type, 0); + if (obj == NULL) { + return PyErr_NoMemory(); + } + _PyObject_DictOrValuesPointer(obj)->dict = NULL; + if (_PyObject_InitInlineValues(obj, type)) { + Py_DECREF(obj); + return NULL; + } + return obj; +} + +PyObject * _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems) { PyObject *obj; |