Repository navigation
translate: drop the uncompressed length from each message - #12010
Merged
Merged
Conversation
Each compressed message started with its uncompressed length (8 bits, 9 for ru). Drop it: the generator pads the last byte with the start of a code longer than the padding, so the decoder stops at the symbol that runs past the end of the data. The length is found by decoding without storing. If a Huffman table has no code long enough to pad with, the generator adds a qstr escape to it.
dhalbert
requested changes
Dec 1, 2026
dhalbert
left a comment
Collaborator
There was a problem hiding this comment.
requests are only for more comments
| s->last = c; | ||
| } | ||
|
|
||
| // UTF-8 encode a code point from the BMP. |
Comment on lines
+665
to
+666
| # compress() pads a message's last byte with the start of a code longer than 7 bits. | ||
| # If a table has none, split its longest code to add a qstr escape. |
Collaborator
There was a problem hiding this comment.
This deserves a little more explanation.
dhalbert
approved these changes
Dec 1, 2026
dhalbert
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the explanations!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #12007. Each compressed message started with its uncompressed length (8 bits, 9 for ru). This drops it. The generator pads the last byte with the start of a code longer than the padding, so the decoder stops at the symbol that runs past the end of the data. The length is found by decoding without storing. If a Huffman table has no code long enough to pad with, the generator adds a qstr escape to it.
All 20 languages build for feather_m0_express. On a PyBadge in de_DE, ja, ko and ru, exception messages, locale and tracebacks match the base build, and the unix coverage tests pass.
Each message is now decoded twice per raise, so raising an exception with a C message is about 30% slower (de_DE: 168 → 222 µs on a PyBadge).
Personally, I find it a bit tricky, but the savings are not bad.
Created with LLM 🤖.