fontations
fontations copied to clipboard
[read-fonts] Micro-optimize a `checked_add` away?
I think I filed this before and closed it, but as I desperately comb through the read-fonts code, it caught my attention again. The following patch seems harmless, as end is checked for wraparound later anyway:
diff --git a/read-fonts/src/font_data.rs b/read-fonts/src/font_data.rs
index fd83483a..2da2db14 100644
--- a/read-fonts/src/font_data.rs
+++ b/read-fonts/src/font_data.rs
@@ -77,9 +77,7 @@ impl<'a> FontData<'a> {
/// Read a scalar at the provided location in the data.
pub fn read_at<T: Scalar>(&self, offset: usize) -> Result<T, ReadError> {
- let end = offset
- .checked_add(T::RAW_BYTE_LEN)
- .ok_or(ReadError::OutOfBounds)?;
+ let end = offset + T::RAW_BYTE_LEN;
self.bytes
.get(offset..end)
.and_then(T::read)