Bug 409342. Cache the last pref font looked up. r=vlad,pavlov, sr=pavlov

This commit is contained in:
jdaggett@mozilla.com 2008-02-11 20:57:57 -08:00
parent 465e2b40ed
commit 512d8be76b
2 changed files with 39 additions and 9 deletions

View File

@ -44,12 +44,14 @@
#include "gfxTypes.h"
#include "gfxFont.h"
#include "gfxFontUtils.h"
#include "gfxPlatform.h"
#include <Carbon/Carbon.h>
class gfxAtsuiFontGroup;
class MacOSFontEntry;
class MacOSFamilyEntry;
class gfxAtsuiFont : public gfxFont {
public:
@ -159,6 +161,12 @@ protected:
/** Returns true for success */
PRBool InitTextRun(gfxTextRun *aRun, const PRUnichar *aString, PRUint32 aLength,
PRBool aWrapped, PRUint32 aSegmentStart, PRUint32 aSegmentLength);
// cache the most recent pref font to avoid general pref font lookup
nsRefPtr<MacOSFamilyEntry> mLastPrefFamily;
nsRefPtr<gfxAtsuiFont> mLastPrefFont;
eFontPrefLang mLastPrefLang; // lang group for last pref font
PRBool mLastPrefFirstFont; // is this the first font in the list of pref fonts for this lang group?
eFontPrefLang mPageLang;
};
#endif /* GFX_ATSUIFONTS_H */

View File

@ -424,6 +424,8 @@ gfxAtsuiFontGroup::gfxAtsuiFontGroup(const nsAString& families,
mFonts.AppendElement(font);
}
}
mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.langGroup.get());
}
PRBool
@ -691,14 +693,19 @@ gfxAtsuiFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
// get the pref font list if it hasn't been set up already
PRUint32 unicodeRange = FindCharUnicodeRange(aCh);
eFontPrefLang charLang = GetFontPrefLangFor(unicodeRange);
eFontPrefLang pageLang = gfxPlatform::GetFontPrefLangFor(mStyle.langGroup.get());
// if the last pref font was the first family in the pref list, no need to recheck through a list of families
if (mLastPrefFont && charLang == mLastPrefLang && mLastPrefFirstFont && mLastPrefFont->TestCharacterMap(aCh)) {
nsRefPtr<gfxAtsuiFont> prefFont = mLastPrefFont;
return prefFont.forget();
}
// based on char lang and page lang, set up list of pref lang fonts to check
eFontPrefLang prefLangs[kMaxLenPrefLangList];
PRUint32 i, numLangs = 0;
gfxPlatformMac *macPlatform = gfxPlatformMac::GetPlatform();
macPlatform->GetLangPrefs(prefLangs, numLangs, charLang, pageLang);
macPlatform->GetLangPrefs(prefLangs, numLangs, charLang, mPageLang);
for (i = 0; i < numLangs; i++) {
nsAutoTArray<nsRefPtr<MacOSFamilyEntry>, 5> families;
@ -721,13 +728,28 @@ gfxAtsuiFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
for (i = 0; i < numPrefs; i++) {
// look up the appropriate face
MacOSFamilyEntry *family = families[i];
if (family) {
MacOSFontEntry *fe = family->FindFont(&mStyle);
// if ch in cmap, create and return a gfxFont
if (fe && fe->TestCharacterMap(aCh)) {
return GetOrMakeFont(fe, &mStyle);
}
if (!family) continue;
// if a pref font is used, it's likely to be used again in the same text run.
// the style doesn't change so the face lookup can be cached rather than calling
// GetOrMakeFont repeatedly. speeds up FindFontForChar lookup times for subsequent
// pref font lookups
if (family == mLastPrefFamily && mLastPrefFont->TestCharacterMap(aCh)) {
nsRefPtr<gfxAtsuiFont> prefFont = mLastPrefFont;
return prefFont.forget();
}
MacOSFontEntry *fe = family->FindFont(&mStyle);
// if ch in cmap, create and return a gfxFont
if (fe && fe->TestCharacterMap(aCh)) {
nsRefPtr<gfxAtsuiFont> prefFont = GetOrMakeFont(fe, &mStyle);
mLastPrefFamily = family;
mLastPrefFont = prefFont;
mLastPrefLang = charLang;
mLastPrefFirstFont == (i == 0);
return prefFont.forget();
}
}
}