Skip to content

Instantly share code, notes, and snippets.

@jdm
Created May 31, 2013 20:48
Show Gist options
  • Save jdm/5687869 to your computer and use it in GitHub Desktop.
Save jdm/5687869 to your computer and use it in GitHub Desktop.
diff --git a/src/components/servo-gfx/font_context.rs b/src/components/servo-gfx/font_context.rs
index 87c1b63..880c7d3 100644
--- a/src/components/servo-gfx/font_context.rs
+++ b/src/components/servo-gfx/font_context.rs
@@ -38,6 +38,7 @@ pub trait FontContextHandleMethods {
pub struct FontContext {
instance_cache: MonoCache<FontDescriptor, @mut Font>,
shaper_cache: MonoCache<FontDescriptor, @Shaper>,
+ group_cache: MonoCache<SpecifiedFontStyle, @FontGroup>,
font_list: Option<FontList>, // only needed by layout
handle: FontContextHandle,
backend: BackendType,
@@ -69,6 +70,8 @@ pub impl<'self> FontContext {
Cache::new::<FontDescriptor,@mut Font,MonoCache<FontDescriptor,@mut Font>>(10),
shaper_cache:
Cache::new::<FontDescriptor,@Shaper,MonoCache<FontDescriptor,@Shaper>>(10),
+ group_cache:
+ Cache::new::<SpecifiedFontStyle,@FontGroup,MonoCache<SpecifiedFontStyle,@FontGroup>>(10),
font_list: font_list,
handle: handle,
backend: backend,
@@ -93,8 +96,13 @@ pub impl<'self> FontContext {
}
fn get_resolved_font_for_style(@mut self, style: &SpecifiedFontStyle) -> @FontGroup {
- // TODO(Issue #178, E): implement a cache of FontGroup instances.
- self.create_font_group(style)
+ match self.group_cache.find(style) {
+ Some(fg) => return fg,
+ None => ()
+ }
+ let result = self.create_font_group(style);
+ self.group_cache.insert(style, result);
+ result
}
fn get_font_by_descriptor(&mut self, desc: &FontDescriptor) -> Result<@mut Font, ()> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment