base64: optimize b16decode - #157310
Conversation
|
bm_base64 in pyperformance: base16_small: Mean +- std dev: [b16-main-commonloop] 278 us +- 1 us -> [b16-changed-commonloop] 219 us +- 2 us: 1.27x faster |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4298ee9383
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if b in s and b not in ignorechars: | ||
| raise binascii.Error('Non-base16 digit found') | ||
| s = s.translate(None, delete=b'abcdef') | ||
| if ignorechars: |
There was a problem hiding this comment.
Check the actual byte length before skipping translation
When ignorechars is a nonempty bytes subclass whose __bool__ returns false, this condition skips the translation even though the lowercase characters must be removed. For example, with such a subclass containing b'a', b16decode(b'aB', ignorechars=...) now decodes the lowercase a as a hex digit and returns b'\xab'; previously a was ignored and the remaining odd digit raised binascii.Error. Normalize bytes subclasses or otherwise test the underlying buffer's emptiness without invoking overridable truthiness.
AGENTS.md reference: AGENTS.md:L16-L16
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
When
ignorecharsis empty, we already know that[a-f]is not present in the byte string, so we skip the call tostr.translate(). Even whenstr.translate()does not modify the string at all, it internally creates a temporary bytes object, so this saves a small amount of time.