Cache font heights in a static fixed array.

This is to avoid significant per-call overhead to get font heights,
as this is performed very frequently.
This commit is contained in:
Jonathan G Rennison
2016-01-01 21:47:34 +00:00
parent b51dd34fe4
commit 5aad0b51a3
3 changed files with 18 additions and 13 deletions

View File

@@ -43,6 +43,7 @@ FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_
{
assert(parent == NULL || this->fs == parent->fs);
FontCache::caches[this->fs] = this;
font_height_cache[this->fs] = this->height;
Layouter::ResetFontCache(this->fs);
}
@@ -54,18 +55,6 @@ FontCache::~FontCache()
Layouter::ResetFontCache(this->fs);
}
/**
* Get height of a character for a given font size.
* @param size Font size to get height of
* @return Height of characters in the given font (pixels)
*/
int GetCharacterHeight(FontSize size)
{
return FontCache::Get(size)->GetHeight();
}
/** Font cache for fonts that are based on a freetype font. */
class SpriteFontCache : public FontCache {
private:
@@ -151,6 +140,7 @@ void SpriteFontCache::InitializeUnicodeGlyphMap()
this->SetUnicodeGlyph(_default_unicode_map[i].code, sprite);
}
}
font_height_cache[this->fs] = this->GetHeight();
}
/**
@@ -197,6 +187,7 @@ bool SpriteFontCache::GetDrawGlyphShadow()
}
/* static */ FontCache *FontCache::caches[FS_END] = { new SpriteFontCache(FS_NORMAL), new SpriteFontCache(FS_SMALL), new SpriteFontCache(FS_LARGE), new SpriteFontCache(FS_MONO) };
int font_height_cache[FS_END];
#ifdef WITH_FREETYPE
#include <ft2build.h>
@@ -312,6 +303,8 @@ FreeTypeFontCache::FreeTypeFontCache(FontSize fs, FT_Face face, int pixels) : Fo
/* Both FT_Set_Pixel_Sizes and FT_Select_Size failed. */
DEBUG(freetype, 0, "Font size selection failed. Using FontCache defaults.");
}
font_height_cache[this->fs] = this->GetHeight();
}
/**