◐ Shell
clean mode source ↗

gh-128213: fast path for bytes creation from list and tuple by eendebakpt · Pull Request #132590 · python/cpython

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PyNumber_AsSsize_t performs an incref/decref on the argument which we can avoid by calling PyLong_AsSsize_t directly (the incref is not very bad, since in the happy path the argument will be in the 0 to 255 range so a python small int, but still). I updated the PR with this approach.

Most important for the PR is making the code thread-safe, so I left the possible optimization with _PyLong_IsNonNegativeCompact out for now.