fontations icon indicating copy to clipboard operation
fontations copied to clipboard

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

Open behdad opened this issue 3 months ago • 0 comments

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?

impl ComputeSize for Class2Record {
    #[allow(clippy::needless_question_mark)]
    fn compute_size(args: &(ValueFormat, ValueFormat)) -> Result<usize, ReadError> {
        let (value_format1, value_format2) = *args;
        let mut result = 0usize;
        result = result
            .checked_add(<ValueRecord as ComputeSize>::compute_size(&value_format1)?)
            .ok_or(ReadError::OutOfBounds)?;
        result = result
            .checked_add(<ValueRecord as ComputeSize>::compute_size(&value_format2)?)
            .ok_or(ReadError::OutOfBounds)?;
        Ok(result)
    }
}

behdad avatar Sep 24 '25 19:09 behdad