8000 gh-129149: Add fast path for medium-size integers in `PyLong_FromSsize_t()` by chris-eibl · Pull Request #129301 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-129149: Add fast path for medium-size integers in PyLong_FromSsize_t() #129301

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 13 commits into from
Mar 13, 2025
Merged
Prev Previous commit
Next Next commit
Address Sergey's review
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
  • Loading branch information
chris-eibl and skirpichev authored Jan 26, 2025
commit 98b3668e43809ce5f1338dd118888e0e7841b6f6
6 changes: 3 additions & 3 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ _PyLong_Negate(PyLongObject **x_p)
return _PyLong_FromMedium((sdigit)ival); \
} \
/* Count digits (at least two - smaller cases were handled above). */ \
abs_ival = ival < 0 ? 0U-(UINT_TYPE)ival : (UINT_TYPE)ival; \
UINT_TYPE abs_ival = ival < 0 ? 0U-(UINT_TYPE)ival : (UINT_TYPE)ival; \
/* Do shift in two steps to avoid possible undefined behavior. */ \
t = abs_ival >> PyLong_SHIFT >> PyLong_SHIFT; \
ndigits = 2; \
UINT_TYPE t = abs_ival >> PyLong_SHIFT >> PyLong_SHIFT; \
int ndigits = 2; \
while (t) { \
++ndigits; \
t >>= PyLong_SHIFT; \
Expand Down
Loading
0