tt_face_get_kerning doing unnecessary linear search for pathological kerning tables
Hello, I noticed that linear search for kerning gets performed unnecessarily for some font files. I am not sure if you are interested in such performance optimizations, so I am opening an issue instead of a merge request.
tt_face_load_kern
decides whether to support binary search of the kerning table based on this loop that makes sure that subsequent pairs have increasing values ( cur_pair <= old_pair )
. As a result, if two consecutive pairs are equal, the table will be treated as not ordered, resulting in linear search being used by tt_face_get_kerning
. However, binary search will work even if the table contains consecutive equal pairs.
So, I am proposing to change the logic from ( cur_pair <= old_pair )
to ( cur_pair < old_pair )
. The only drawback to this check would be that tt_face_get_kerning
will end up returning potentially different results for such table entries, since before it would return the first encountered value, while after the change it will return one of the equivalent entries, depending on where the binary search ends up stopping.
Thanks,
Boyan