Skip to content

Commit

Permalink
fontique: Remove unsafe in fontconfig cache
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 committed Jun 15, 2024
1 parent 14f7116 commit 4b22e53
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions fontique/src/backend/fontconfig/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn parse_font(
let leaf = leaf.ok()?;
font.coverage
.leaves
.push(unsafe { core::mem::transmute(leaf) });
.push(leaf);
}
}
}
Expand All @@ -213,7 +213,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 +230,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 4b22e53

Please sign in to comment.