Skip to content
Closed
Show file tree
Hide file tree
Changes from 15 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Slightly optimize the :class:`int` deallocator by removing a redundant check.
6 changes: 6 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3614,9 +3614,13 @@ long_richcompare(PyObject *self, PyObject *other, int op)
static void
long_dealloc(PyObject *self)
{
#ifdef Py_LIMITED_API
#ifndef Py_GIL_DISABLED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's possible for us to know when we're using the limited API. Py_LIMITED_API is something that affects Python.h at the compile-time of an extension module, but this happens during the compilation of CPython, so it will never be true.

/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
PyLongObject *pylong = (PyLongObject*)self;
if (pylong && _PyLong_IsCompact(pylong)) {
Expand All @@ -3629,6 +3633,8 @@ long_dealloc(PyObject *self)
}
}
}
#endif
#endif
Py_TYPE(self)->tp_free(self);
}

Expand Down
Loading