font get optimisation

This commit is contained in:
Corwin 2023-07-04 21:35:00 +01:00
parent 991bb644f9
commit 0cd469866c
No known key found for this signature in database

View file

@ -47,14 +47,14 @@ impl FontLetter {
} }
pub struct Font { pub struct Font {
letters: &'static [FontLetter], letters: &'static [FontLetter; 128],
line_height: i32, line_height: i32,
ascent: i32, ascent: i32,
} }
impl Font { impl Font {
#[must_use] #[must_use]
pub const fn new(letters: &'static [FontLetter], line_height: i32, ascent: i32) -> Self { pub const fn new(letters: &'static [FontLetter; 128], line_height: i32, ascent: i32) -> Self {
Self { Self {
letters, letters,
line_height, line_height,
@ -63,7 +63,7 @@ impl Font {
} }
pub(crate) fn letter(&self, letter: char) -> &'static FontLetter { pub(crate) fn letter(&self, letter: char) -> &'static FontLetter {
&self.letters[letter as usize] &self.letters[letter as usize & (128 - 1)]
} }
pub(crate) fn ascent(&self) -> i32 { pub(crate) fn ascent(&self) -> i32 {