mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-127119: Faster check for small ints in long_dealloc (GH-127620)
This commit is contained in:
parent
3a974e39d5
commit
a29221675e
6 changed files with 48 additions and 45 deletions
|
@ -1,5 +1,8 @@
|
|||
#include "parts.h"
|
||||
|
||||
#define Py_BUILD_CORE
|
||||
#include "internal/pycore_long.h" // IMMORTALITY_BIT_MASK
|
||||
|
||||
int verify_immortality(PyObject *object)
|
||||
{
|
||||
assert(_Py_IsImmortal(object));
|
||||
|
@ -26,7 +29,17 @@ static PyObject *
|
|||
test_immortal_small_ints(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
for (int i = -5; i <= 256; i++) {
|
||||
assert(verify_immortality(PyLong_FromLong(i)));
|
||||
PyObject *obj = PyLong_FromLong(i);
|
||||
assert(verify_immortality(obj));
|
||||
int has_int_immortal_bit = ((PyLongObject *)obj)->long_value.lv_tag & IMMORTALITY_BIT_MASK;
|
||||
assert(has_int_immortal_bit);
|
||||
}
|
||||
for (int i = 257; i <= 260; i++) {
|
||||
PyObject *obj = PyLong_FromLong(i);
|
||||
assert(obj);
|
||||
int has_int_immortal_bit = ((PyLongObject *)obj)->long_value.lv_tag & IMMORTALITY_BIT_MASK;
|
||||
assert(!has_int_immortal_bit);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue