Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 17 additions & 1 deletion Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,26 @@ static inline int _PyObject_GC_IS_TRACKED(PyObject *op) {
}
#define _PyObject_GC_IS_TRACKED(op) _PyObject_GC_IS_TRACKED(_Py_CAST(PyObject*, op))

// Fast inlined version of PyType_IS_GC()
static inline int
_PyType_IS_GC(PyTypeObject *type)
{
return (type->tp_flags & Py_TPFLAGS_HAVE_GC) != 0;
}

// Fast inlined version of PyObject_IS_GC()
static inline int
_PyObject_IS_GC(PyObject *obj)
{
PyTypeObject *type = Py_TYPE(obj);
return (_PyType_IS_GC(type)
&& (type->tp_is_gc == NULL || type->tp_is_gc(obj)));
}

/* True if the object may be tracked by the GC in the future, or already is.
This can be useful to implement some optimizations. */
static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) {
if (!PyObject_IS_GC(obj)) {
if (!_PyObject_IS_GC(obj)) {
return 0;
}
if (PyTuple_CheckExact(obj)) {
Expand Down
12 changes: 0 additions & 12 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,18 +816,6 @@ _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(PyObject *op)
return (PyWeakReference **)((char *)op + offset);
}

// Fast inlined version of PyType_IS_GC()
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)

// Fast inlined version of PyObject_IS_GC()
static inline int
_PyObject_IS_GC(PyObject *obj)
{
PyTypeObject *type = Py_TYPE(obj);
return (_PyType_IS_GC(type)
&& (type->tp_is_gc == NULL || type->tp_is_gc(obj)));
}

// Fast inlined version of PyObject_Hash(). Dictionaries are very
// likely to include string keys (class and instance attributes,
// json, ...) so we include a fast path for strings.
Expand Down
Loading