Branch: refs/heads/glyf-setitem-perf
Home:
https://github.com/fonttools/fonttools
Commit: 431ca5771611e98cfe06876802fa8ee11485ca28
https://github.com/fonttools/fonttools/commit/431ca5771611e98cfe06876802fa8ee11485ca28
Author: Cosimo Lupo <
cos...@anthrotype.com>
Date: 2026-06-17 (Wed, 17 Jun 2026)
Changed paths:
M Lib/fontTools/ttLib/tables/_g_l_y_f.py
M Tests/ttLib/tables/_g_l_y_f_test.py
Log Message:
-----------
[glyf] Use reverse glyph map for O(1) __setitem__ membership
table__g_l_y_f.__setitem__ tested `glyphName not in self.glyphOrder`, a linear
scan of the glyphOrder list on every assignment, so repeatedly assigning glyphs
over a pre-populated glyphOrder was O(n^2) in the glyph count -- several seconds
of pure scanning for a 60k-glyph font.
Use the reverse glyph map (_reverseGlyphOrder) for O(1) membership instead,
rebuilding it when it is missing or its length no longer matches glyphOrder, and
invalidating it on __delitem__. Reordering goes through setGlyphOrder, which
already clears the map; editing glyphOrder directly behind the table's back is
unsupported.
Related to #2605, a separate correctness issue (the TTFont-level
_reverseGlyphOrderDict going stale, see #3582), not changed here.
To unsubscribe from these emails, change your notification settings at
https://github.com/fonttools/fonttools/settings/notifications