Title: bpo-46311: Clean up PyLong_FromLong and PyLong_FromLongLong by mdickinson · Pull Request #30496 · python/cpython · GitHub
Open Graph Title: bpo-46311: Clean up PyLong_FromLong and PyLong_FromLongLong by mdickinson · Pull Request #30496 · python/cpython
X Title: bpo-46311: Clean up PyLong_FromLong and PyLong_FromLongLong by mdickinson · Pull Request #30496 · python/cpython
Description: PR #27832 inadvertently introduced a couple of changes to PyLong_FromLong that didn't make a lot of sense: an (unsigned long) cast was replaced with (twodigits), and a digit count variable (counting number of PyLong digits in a C long) had its type needlessly changed from int to Py_ssize_t. The first change is a potential portability bug, but only on platforms with 128-bit longs. The (unsigned long) cast is obviously correct, while figuring out whether (twodigits) loses information takes some work. The second change is merely a potential pessimization: there's no need to use what's typically a 64-bit integer to count the number of PyLong digits in a long. This PR: reverts those two changes moves the check for medium values earlier in the function (immediately after the small values check), and simplifies that check makes the code a bit less branchy (from experiments locally and on godbolt.org, the expression ival < 0 ? 0U-(unsigned long)ival : ival) gets compiled to something branchless on most platforms, as does ival < 0 ? -ndigits : ndigits introduces parallel changes for PyLong_FromLongLong, which now has a fast path for medium-size values. https://bugs.python.org/issue46311
Open Graph Description: PR #27832 inadvertently introduced a couple of changes to PyLong_FromLong that didn't make a lot of sense: an (unsigned long) cast was replaced with (twodigits), and a digit count variable (cou...
X Description: PR #27832 inadvertently introduced a couple of changes to PyLong_FromLong that didn't make a lot of sense: an (unsigned long) cast was replaced with (twodigits), and a digit count variable ...
Opengraph URL: https://github.com/python/cpython/pull/30496
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:7af3db78-5742-8dbe-fcc3-175c21163af0 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 94FA:BAE66:83578C:BA3FD0:696A518D |
| html-safe-nonce | 5baf5f754896fbc4790bc8b4c374252540cae252ffbe8dc02d33dc5c5f387897 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEZBOkJBRTY2OjgzNTc4QzpCQTNGRDA6Njk2QTUxOEQiLCJ2aXNpdG9yX2lkIjoiMjI4NzY1NzgxNDUwODMyNzMwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 404b67de79388be83da7bb0f0950e58addbc7c9889eb253159678337c16197fd |
| hovercard-subject-tag | pull_request:817013592 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/30496/checks |
| twitter:image | https://avatars.githubusercontent.com/u/662003?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/662003?s=400&v=4 |
| og:image:alt | PR #27832 inadvertently introduced a couple of changes to PyLong_FromLong that didn't make a lot of sense: an (unsigned long) cast was replaced with (twodigits), and a digit count variable (cou... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width