ascii optimization

This commit is contained in:
Glenn Maynard
2004-10-01 17:25:17 +00:00
parent c08e4ecdbd
commit 0e7c5a7141
2 changed files with 17 additions and 0 deletions
+16
View File
@@ -270,6 +270,12 @@ void Font::MergeFont(Font &f)
const glyph &Font::GetGlyph( wchar_t c ) const
{
ASSERT(c >= 0 && c <= 0xFFFFFF);
/* Fast path: */
if( c < (int) ARRAYSIZE(m_iCharToGlyphCache) && m_iCharToGlyphCache[c] )
return *m_iCharToGlyphCache[c];
/* Try the regular character. */
map<longchar,glyph*>::const_iterator it = m_iCharToGlyph.find(c);
@@ -842,6 +848,16 @@ void Font::Load(const CString &sFontOrTextureFilePath, CString sChars)
LOG->Warn("Font %s has no characters", sFontOrTextureFilePath.c_str());
LoadStack.pop_back();
if( LoadStack.empty() )
{
/* Cache ASCII glyphs. */
ZERO( m_iCharToGlyphCache );
map<longchar,glyph*>::iterator it;
for( it = m_iCharToGlyph.begin(); it != m_iCharToGlyph.end(); ++it )
if( it->first < (int) ARRAYSIZE(m_iCharToGlyphCache) )
m_iCharToGlyphCache[it->first] = it->second;
}
}
/*
+1
View File
@@ -144,6 +144,7 @@ private:
/* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */
map<longchar,glyph*> m_iCharToGlyph;
glyph *m_iCharToGlyphCache[128];
/* We keep this around only for reloading. */
CString Chars;