Cache None for code points not found in font to prevent unnecessary file scans#76
Merged
Merged
Conversation
519a1df to
3bfc80a
Compare
…ile scans The current implementation treats None as meaning not present in the font OR never before loaded rather than simply not present in the font. This means that a subsequent call to load_glyphs for a code point that had been loaded before and not found will trigger another scan of the file, only to not be found again. This commit: 1. Changes the meaning of None in the cache to mean simply not present in the font. 2. In the BDF and PCF implementations, caches None for code points not found in the font. The lvfontbin implementation already does this. The TTF implementation doesn't load glyphs so this is not yet relevant. 3. Removes the preemptive caching of None in get_glyph. 4. Adds tests. There were already mocks written for displayio.Bitmap and fontio.Glyph so the tests use those. This commit also cleans up and clarifies type checking imports so that tests run using the mocked displayio.Bitmap. Closes adafruit#75
CI only runs tests if the dir tests/ is present.
45534d5 to
3a8c0a4
Compare
mtraver
commented
May 21, 2026
tannewt
approved these changes
May 21, 2026
Member
tannewt
left a comment
There was a problem hiding this comment.
Thank you! Excited for the speedup 🚀
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.
The current implementation treats
Noneas meaning not present in the font OR never before loaded rather than simply not present in the font. This means that a subsequent call toload_glyphsfor a code point that had been loaded before and not found will trigger another scan of the file, only to not be found again.This PR:
Nonein the cache to mean simply not present in the font.Nonefor code points not found in the font. The lvfontbin implementation already does this. The TTF implementation doesn't load glyphs so this is not yet relevant.Noneinget_glyph.displayio.Bitmapandfontio.Glyphso the tests use those. The test/ dir is also renamed to tests/ because CI only runs pytest if the dir tests/ is present.This PR also cleans up and clarifies type checking imports so that tests run using the mocked
displayio.Bitmap.Finally, there were changes required by the
ruff checkpre-commit check, so some type annotations are updated from e.g.Optional[int]toint | Noneetc.Closes #75