FT_GlyphLoader_CheckPoints builds outlines inefficiently.
FT_GlyphLoader_CheckPoints
is used to expand the storage of the loader's base outline. When the storage is expanded it is only expanded through a realloc to the size currently needed. As a result when adding points many times to an outline this takes n^2 time. Instead, FT_GlyphLoader_CheckPoints
should expand the storage by at least some multiple of the current size when it needs to grow. This would allow for amortized constant time in building the outline. This part is mostly straight forward, but it may be desirable to also trim the outline's storage when the outline is complete. This is made somewhat difficult by the ownership of the FT_GlyphLoader
's outlines, which makes it difficult to tell when ownership logically passed from the loader to the glyph and the outline is complete.
This was noticed while investigating a fuzzer timeout at https://bugs.chromium.org/p/chromium/issues/detail?id=1342213 . The recent change 1a242558 made this situation more likely to time out by more aggressively shrinking (freeing) the loader's base outline allocations (and setting max_points to 0). This means that the loaders base outline storage must be expanded every time after an error instead of expanding to a large size and the large size being re-used.