8000 GH-129149: Add fast paths to four more `PyLong_From*` functions by chris-eibl · Pull Request #131211 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-129149: Add fast paths to four more PyLong_From* functions #131211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2025
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
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 12 additions & 4 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6742,16 +6742,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 { \
Expand Down
Loading
0