Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[read-fonts] fix ClassDefFormat2::get() #755

Merged
merged 2 commits into from
Jan 15, 2024
Merged

[read-fonts] fix ClassDefFormat2::get() #755

merged 2 commits into from
Jan 15, 2024

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Jan 13, 2024

The conditional logic for selecting the appropriate class record was not quite right leading to incorrect class values being returned. This implements the lookup using a binary search and adds a test for correct behavior.

JMM

The conditional logic for selecting the appropriate class record was not quite right leading to incorrect class values being returned. This implements the lookup using a binary search and adds a test for correct behavior.
@cmyr
Copy link
Member

cmyr commented Jan 13, 2024

oops, good catch! Maybe an argument for writing things like this as, (record.start_gid()..=record.end_gid()).contains(gid), which is easier to grok.

Also a number of years back I wrote up some simple benchmarks comparing binary and linear search for an integer over a range of collection sizes, and although I don't recall the exact numbers, linear search was winning up to some reasonable collection length, like ~16, and my conclusion was that if you know your collection length is unlikely to be huge than linear is preferable. (Now I'm curious, and maybe I should go recreate that code and find out if I'm remebering correctly)

@dfrg
Copy link
Member Author

dfrg commented Jan 15, 2024

oops, good catch! Maybe an argument for writing things like this as, (record.start_gid()..=record.end_gid()).contains(gid), which is easier to grok.

Good call! Changed to use Range::contains for the final check.

Also a number of years back I wrote up some simple benchmarks comparing binary and linear search for an integer over a range of collection sizes, and although I don't recall the exact numbers, linear search was winning up to some reasonable collection length, like ~16, and my conclusion was that if you know your collection length is unlikely to be huge than linear is preferable. (Now I'm curious, and maybe I should go recreate that code and find out if I'm remebering correctly)

A lot of ranged based classdef (and coverage) tables have a handful of entries and I'm definitely willing to believe a linear search is faster for some n (and 16 sounds like the right ballpark). This is probably an area worth doing some perf exploration in the future as these tables are going to be in heavy use in a shaper.

@dfrg dfrg merged commit 74bdb79 into main Jan 15, 2024
9 checks passed
@dfrg dfrg deleted the classdef-get-fix branch January 15, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants