Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize `TextRun::advance_for_range`. #8990

Merged
merged 3 commits into from Dec 17, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

gfx: Cache the total advance of each glyph store.

The total advance is asked for over and over.
  • Loading branch information
pcwalton committed Dec 15, 2015
commit 85c73deb787ee171ee3cc7fb6c1cbd1e74548056
@@ -403,6 +403,9 @@ pub struct GlyphStore {
/// `entry_buffer` point to locations in this data structure.
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.
has_detailed_glyphs: bool,
is_whitespace: bool,
@@ -427,6 +430,7 @@ impl<'a> GlyphStore {
GlyphStore {
entry_buffer: vec![GlyphEntry::initial(); length],
detail_store: DetailedGlyphStore::new(),
total_advance: Au(0),
has_detailed_glyphs: false,
is_whitespace: is_whitespace,
is_rtl: is_rtl,
@@ -443,6 +447,20 @@ impl<'a> GlyphStore {

pub fn finalize_changes(&mut self) {
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;
@@ -532,7 +550,9 @@ impl<'a> GlyphStore {

#[inline]
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)
} else {
self.advance_for_char_range_slow_path(rang)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.