mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
gfx: Cache the total advance of each glyph store.
The total advance is asked for over and over.
This commit is contained in:
parent
6f2aa54120
commit
85c73deb78
1 changed files with 21 additions and 1 deletions
|
@ -403,6 +403,9 @@ pub struct GlyphStore {
|
||||||
/// `entry_buffer` point to locations in this data structure.
|
/// `entry_buffer` point to locations in this data structure.
|
||||||
detail_store: DetailedGlyphStore,
|
detail_store: DetailedGlyphStore,
|
||||||
|
|
||||||
|
/// A cache of the advance of the entire glyph store.
|
||||||
|
total_advance: Au,
|
||||||
|
|
||||||
/// Used to check if fast path should be used in glyph iteration.
|
/// Used to check if fast path should be used in glyph iteration.
|
||||||
has_detailed_glyphs: bool,
|
has_detailed_glyphs: bool,
|
||||||
is_whitespace: bool,
|
is_whitespace: bool,
|
||||||
|
@ -427,6 +430,7 @@ impl<'a> GlyphStore {
|
||||||
GlyphStore {
|
GlyphStore {
|
||||||
entry_buffer: vec![GlyphEntry::initial(); length],
|
entry_buffer: vec![GlyphEntry::initial(); length],
|
||||||
detail_store: DetailedGlyphStore::new(),
|
detail_store: DetailedGlyphStore::new(),
|
||||||
|
total_advance: Au(0),
|
||||||
has_detailed_glyphs: false,
|
has_detailed_glyphs: false,
|
||||||
is_whitespace: is_whitespace,
|
is_whitespace: is_whitespace,
|
||||||
is_rtl: is_rtl,
|
is_rtl: is_rtl,
|
||||||
|
@ -443,6 +447,20 @@ impl<'a> GlyphStore {
|
||||||
|
|
||||||
pub fn finalize_changes(&mut self) {
|
pub fn finalize_changes(&mut self) {
|
||||||
self.detail_store.ensure_sorted();
|
self.detail_store.ensure_sorted();
|
||||||
|
self.cache_total_advance()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn cache_total_advance(&mut self) {
|
||||||
|
let mut total_advance = Au(0);
|
||||||
|
for glyph in self.iter_glyphs_for_char_range(&Range::new(CharIndex(0), self.char_len())) {
|
||||||
|
total_advance = total_advance + glyph.advance()
|
||||||
|
}
|
||||||
|
self.total_advance = total_advance
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn total_advance(&self) -> Au {
|
||||||
|
self.total_advance
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a single glyph. If `character` is present, this represents a single character;
|
/// Adds a single glyph. If `character` is present, this represents a single character;
|
||||||
|
@ -532,7 +550,9 @@ impl<'a> GlyphStore {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn advance_for_char_range(&self, rang: &Range<CharIndex>) -> Au {
|
pub fn advance_for_char_range(&self, rang: &Range<CharIndex>) -> Au {
|
||||||
if !self.has_detailed_glyphs {
|
if rang.begin() == CharIndex(0) && rang.end() == self.char_len() {
|
||||||
|
self.total_advance
|
||||||
|
} else if !self.has_detailed_glyphs {
|
||||||
self.advance_for_char_range_simple_glyphs(rang)
|
self.advance_for_char_range_simple_glyphs(rang)
|
||||||
} else {
|
} else {
|
||||||
self.advance_for_char_range_slow_path(rang)
|
self.advance_for_char_range_slow_path(rang)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue