https://github.com/python/cpython/commit/a175d64e30b0ff9f011aea2da6d6e21ccfdcd893 commit: a175d64e30b0ff9f011aea2da6d6e21ccfdcd893 branch: main author: Chris Eibl <138194463+chris-e...@users.noreply.github.com> committer: picnixz <10796600+picn...@users.noreply.github.com> date: 2025-03-30T10:12:42+02:00 summary:
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}`. files: A Misc/NEWS.d/next/Core_and_Builtins/2025-03-13-20-23-02.gh-issue-129149.z42wkm.rst M Objects/longobject.c diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-13-20-23-02.gh-issue-129149.z42wkm.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-13-20-23-02.gh-issue-129149.z42wkm.rst new file mode 100644 index 00000000000000..9da77312cbb22d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-13-20-23-02.gh-issue-129149.z42wkm.rst @@ -0,0 +1,4 @@ +Add fast path for small and medium-size integers in +:c:func:`PyLong_FromInt32`, :c:func:`PyLong_FromUInt32`, +:c:func:`PyLong_FromInt64` and +:c:func:`PyLong_FromUInt64`. Patch by Chris Eibl. diff --git a/Objects/longobject.c b/Objects/longobject.c index 984381ff4969d0..d0c3bb145ac28d 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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 { \ _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com