GH-129149: Add fast path for medium-sized integers in PyLong_From* functions (#131211)

Add a fast path for medium-sized integers in `PyLong_FromInt{32,64}` and `PyLong_FromUInt{32,64}`.
This commit is contained in:
Chris Eibl 2025-03-30 10:12:42 +02:00 committed by GitHub
parent 425f60b9eb
commit a175d64e30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -6749,16 +6749,24 @@ PyUnstable_Long_CompactValue(const PyLongObject* op) {
PyObject* PyLong_FromInt32(int32_t value)
{ return PyLong_FromNativeBytes(&value, sizeof(value), -1); }
{
PYLONG_FROM_INT(uint32_t, int32_t, value);
}
PyObject* PyLong_FromUInt32(uint32_t value)
{ return PyLong_FromUnsignedNativeBytes(&value, sizeof(value), -1); }
{
PYLONG_FROM_UINT(uint32_t, value);
}
PyObject* PyLong_FromInt64(int64_t value)
{ return PyLong_FromNativeBytes(&value, sizeof(value), -1); }
{
PYLONG_FROM_INT(uint64_t, int64_t, value);
}
PyObject* PyLong_FromUInt64(uint64_t value)
{ return PyLong_FromUnsignedNativeBytes(&value, sizeof(value), -1); }
{
PYLONG_FROM_UINT(uint64_t, value);
}
#define LONG_TO_INT(obj, value, type_name) \
do { \