ascii optimization
This commit is contained in:
@@ -270,6 +270,12 @@ void Font::MergeFont(Font &f)
|
|||||||
|
|
||||||
const glyph &Font::GetGlyph( wchar_t c ) const
|
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. */
|
/* Try the regular character. */
|
||||||
map<longchar,glyph*>::const_iterator it = m_iCharToGlyph.find(c);
|
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());
|
LOG->Warn("Font %s has no characters", sFontOrTextureFilePath.c_str());
|
||||||
|
|
||||||
LoadStack.pop_back();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ private:
|
|||||||
|
|
||||||
/* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */
|
/* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */
|
||||||
map<longchar,glyph*> m_iCharToGlyph;
|
map<longchar,glyph*> m_iCharToGlyph;
|
||||||
|
glyph *m_iCharToGlyphCache[128];
|
||||||
|
|
||||||
/* We keep this around only for reloading. */
|
/* We keep this around only for reloading. */
|
||||||
CString Chars;
|
CString Chars;
|
||||||
|
|||||||
Reference in New Issue
Block a user