Skip to content

Commit

Permalink
fontique: Remove unsafe in fontconfig cache (#78)
Browse files Browse the repository at this point in the history
Instead of transmuting the `CharSetLeaf` to the underlying value and
then doing the operations on that, use the operation as already exposed
via `CharSetLeaf::contains_byte`.
  • Loading branch information
waywardmonkeys authored Jun 16, 2024
1 parent 14f7116 commit e2102bf
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions fontique/src/backend/fontconfig/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ fn parse_font(
.extend_from_slice(set.numbers().ok()?.as_slice().ok()?);
for leaf in set.leaves().ok()? {
let leaf = leaf.ok()?;
font.coverage
.leaves
.push(unsafe { core::mem::transmute(leaf) });
font.coverage.leaves.push(leaf);
}
}
}
Expand All @@ -213,7 +211,7 @@ fn parse_font(
#[derive(Clone, Default)]
pub struct Coverage {
numbers: Vec<u16>,
leaves: Vec<[u32; 8]>,
leaves: Vec<CharSetLeaf>,
}

impl Coverage {
Expand All @@ -230,9 +228,7 @@ impl Coverage {
Ok(idx) => {
let leaf = self.leaves.get(idx)?;
let lo = (ch & 0xff) as u8;
let map_idx = (lo >> 5) as usize;
let bit_idx = (lo & 0x1f) as u32;
Some((leaf[map_idx] >> bit_idx) & 1 != 0)
Some(leaf.contains_byte(lo))
}
Err(_) => Some(false),
}
Expand Down

0 comments on commit e2102bf

Please sign in to comment.