googlefonts / googlefonts/fontations

[read-fonts] ValueFormat compute_size doesn't need checked_add

Open
#1,668 0 comments 0 reactions 0 assignees View on GitHub
performance
Dominant language
Rust
Stars
826
Forks
75
Avg merge
22h 33m
Merged PRs (30d)
75

Description

This `generated_gpos.rs` snippet is showing `checked_add` taking 0.6% in my Roboto HarfRust benchmark, whereas we know these values are small and can't possibly overflow. Can we fix this?
```rust
impl ComputeSize for Class2Record {
#[allow(clippy::needless_question_mark)]
fn compute_size(args: &(ValueFormat, ValueFormat)) -> Result {
let (value_format1, value_format2) = *args;
let mut result = 0usize;
result = result
.checked_add(::compute_size(&value_format1)?)
.ok_or(ReadError::OutOfBounds)?;
result = result
.checked_add(::compute_size(&value_format2)?)
.ok_or(ReadError::OutOfBounds)?;
Ok(result)
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the generated_gpos.rs implementation of ComputeSize for Class2Record and inspect how this generated code is produced. Remove the unnecessary checked_add handling for the two ValueRecord sizes while preserving the Result return type, then run the relevant Rust tests or benchmark to confirm the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.