Grab a low hanging perf fruit by switching to an API that doesn't copy the font, b=118918, r=dbaron, sr=waterson

git-svn-id: svn://10.0.0.236/trunk@111752 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rbs%maths.uq.edu.au 2002-01-10 00:04:35 +00:00
parent 90bea81de4
commit 13b4696963
11 changed files with 81 additions and 83 deletions

View File

@ -1589,9 +1589,9 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aConte
switch (aSID) {
case eStyleStruct_Font:
{
nsFont defaultFont;
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
nsStyleFont* fontData = new (mPresContext) nsStyleFont(defaultFont);
const nsFont* defaultFont;
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
nsStyleFont* fontData = new (mPresContext) nsStyleFont(*defaultFont);
aContext->SetStyle(eStyleStruct_Font, *fontData);
return fontData;
}
@ -1768,9 +1768,10 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
const nsFont& aDefaultFont, const nsStyleFont* aParentFont,
nsStyleFont* aFont, PRBool& aInherited)
{
nsFont defaultVariableFont, defaultFixedFont;
aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultVariableFont);
aPresContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, defaultFixedFont);
const nsFont* defaultVariableFont;
const nsFont* defaultFixedFont;
aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultVariableFont);
aPresContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, &defaultFixedFont);
// font-family: string list, enum, inherit
if (eCSSUnit_String == aFontData.mFamily.GetUnit()) {
@ -1832,9 +1833,9 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
aPresContext->GetDeviceContext(getter_AddRefs(dc));
if (dc) {
// GetSystemFont sets the font face but not necessarily the size
aFont->mFont.size = defaultVariableFont.size;
aFont->mFont.size = defaultVariableFont->size;
if (NS_FAILED(dc->GetSystemFont(sysID, &aFont->mFont))) {
aFont->mFont.name = defaultVariableFont.name;
aFont->mFont.name = defaultVariableFont->name;
}
aFont->mSize = aFont->mFont.size; // this becomes our cascading size
}
@ -1846,11 +1847,11 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
case eSystemFont_Field:
case eSystemFont_List:
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
break;
case eSystemFont_Button:
aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));
aFont->mSize = defaultVariableFont.size;
aFont->mSize = defaultVariableFont->size;
break;
}
}
@ -1878,10 +1879,10 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
case eSystemFont_Field:
if (eCompatibility_NavQuirks == mode) {
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
} else {
// Assumption: system defined font is proportional
aFont->mSize = PR_MAX(defaultVariableFont.size - NSIntPointsToTwips(2), 0);
aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);
}
break;
//
@ -1902,7 +1903,7 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
aFont->mFont.name.Assign(NS_LITERAL_STRING("sans-serif"));
}
// Assumption: system defined font is proportional
aFont->mSize = PR_MAX(defaultVariableFont.size - NSIntPointsToTwips(2), 0);
aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);
break;
}
#endif
@ -1912,12 +1913,12 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
switch (sysID) {
case eSystemFont_Field:
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
break;
case eSystemFont_Button:
case eSystemFont_List:
aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));
aFont->mSize = defaultVariableFont.size;
aFont->mSize = defaultVariableFont->size;
break;
default:
NS_ERROR("unexpected SID");
@ -2086,9 +2087,9 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
// If we stopped earlier because we reached the root of the style tree,
// we will start with the default generic font from the presentation
// context. Otherwise we start with the higher context.
nsFont defaultFont;
aPresContext->GetDefaultFont(aGenericFontID, defaultFont);
nsStyleFont parentFont(defaultFont);
const nsFont* defaultFont;
aPresContext->GetDefaultFont(aGenericFontID, &defaultFont);
nsStyleFont parentFont(*defaultFont);
PRInt32 i = contextPath.Count() - 1;
if (higherContext) {
nsIStyleContext* context = (nsIStyleContext*)contextPath[i];
@ -2134,7 +2135,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
SetFont(aPresContext, context, aMinFontSize,
aUseDocumentFonts, aChromeOverride, PR_TRUE,
fontData, defaultFont, &parentFont, aFont, dummy);
fontData, *defaultFont, &parentFont, aFont, dummy);
// XXX Not sure if we need to do this here
// If we have a post-resolve callback, handle that now.
@ -2151,7 +2152,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
// can just compute the delta from the parent.
SetFont(aPresContext, aContext, aMinFontSize,
aUseDocumentFonts, aChromeOverride, PR_TRUE,
aFontData, defaultFont, &parentFont, aFont, dummy);
aFontData, *defaultFont, &parentFont, aFont, dummy);
}
const nsStyleStruct*
@ -2187,10 +2188,10 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
}
}
nsFont defaultFont;
const nsFont* defaultFont;
if (!font) {
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
font = new (mPresContext) nsStyleFont(defaultFont);
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
font = new (mPresContext) nsStyleFont(*defaultFont);
}
if (!parentFont)
parentFont = font;
@ -2256,10 +2257,10 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
// continue the normal processing
// our default font is the most recent generic font
generic = parentFont->mFlags & NS_STYLE_FONT_FACE_MASK;
mPresContext->GetDefaultFont(generic, defaultFont);
mPresContext->GetDefaultFont(generic, &defaultFont);
SetFont(mPresContext, aContext, minimumFontSize,
useDocumentFonts, chromeOverride, PR_FALSE,
fontData, defaultFont, parentFont, font, inherited);
fontData, *defaultFont, parentFont, font, inherited);
}
else {
// re-calculate the font as a generic font

View File

@ -905,9 +905,9 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame,
const nsString& fontName = font->mFont.name;
PRUint8 generic = font->mFlags & NS_STYLE_FONT_FACE_MASK;
if (generic == kGenericFont_NONE) {
nsFont defaultFont;
presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
PRInt32 lendiff = fontName.Length() - defaultFont.name.Length();
const nsFont* defaultFont;
presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
PRInt32 lendiff = fontName.Length() - defaultFont->name.Length();
if (lendiff > 0) {
val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma
} else {

View File

@ -588,18 +588,14 @@ NS_IMETHODIMP mozXMLTerminal::ScreenSize(PRInt32* rows, PRInt32* cols,
return result;
// Get the default fixed pitch font
nsFont defaultFixedFont("dummyfont", NS_FONT_STYLE_NORMAL,
NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL,
NS_FONT_DECORATION_NONE, 16);
result = presContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, defaultFixedFont);
const nsFont* defaultFixedFont;
result = presContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, &defaultFixedFont);
if (NS_FAILED(result))
return result;
// Get metrics for fixed font
nsCOMPtr<nsIFontMetrics> fontMetrics;
result = presContext->GetMetricsFor(defaultFixedFont,
result = presContext->GetMetricsFor(*defaultFixedFont,
getter_AddRefs(fontMetrics));
if (NS_FAILED(result) || !fontMetrics)
return result;

View File

@ -1108,32 +1108,32 @@ nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult)
}
NS_IMETHODIMP
nsPresContext::GetDefaultFont(PRUint8 aFontID, nsFont& aResult)
nsPresContext::GetDefaultFont(PRUint8 aFontID, const nsFont** aResult)
{
nsresult rv = NS_OK;
switch (aFontID) {
// Special (our default variable width font and fixed width font)
case kPresContext_DefaultVariableFont_ID:
aResult = mDefaultVariableFont;
*aResult = &mDefaultVariableFont;
break;
case kPresContext_DefaultFixedFont_ID:
aResult = mDefaultFixedFont;
*aResult = &mDefaultFixedFont;
break;
// CSS
case kGenericFont_serif:
aResult = mDefaultSerifFont;
*aResult = &mDefaultSerifFont;
break;
case kGenericFont_sans_serif:
aResult = mDefaultSansSerifFont;
*aResult = &mDefaultSansSerifFont;
break;
case kGenericFont_monospace:
aResult = mDefaultMonospaceFont;
*aResult = &mDefaultMonospaceFont;
break;
case kGenericFont_cursive:
aResult = mDefaultCursiveFont;
*aResult = &mDefaultCursiveFont;
break;
case kGenericFont_fantasy:
aResult = mDefaultFantasyFont;
*aResult = &mDefaultFantasyFont;
break;
default:
rv = NS_ERROR_INVALID_ARG;

View File

@ -265,7 +265,7 @@ public:
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0;
/** Get the default font correponding to the given ID */
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, nsFont& aResult) = 0;
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, const nsFont** aResult) = 0;
/** Set the default font correponding to the given ID */
NS_IMETHOD SetDefaultFont(PRUint8 aFontID, const nsFont& aFont) = 0;

View File

@ -265,7 +265,7 @@ public:
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0;
/** Get the default font correponding to the given ID */
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, nsFont& aResult) = 0;
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, const nsFont** aResult) = 0;
/** Set the default font correponding to the given ID */
NS_IMETHOD SetDefaultFont(PRUint8 aFontID, const nsFont& aFont) = 0;

View File

@ -265,7 +265,7 @@ public:
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) = 0;
/** Get the default font correponding to the given ID */
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, nsFont& aResult) = 0;
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, const nsFont** aResult) = 0;
/** Set the default font correponding to the given ID */
NS_IMETHOD SetDefaultFont(PRUint8 aFontID, const nsFont& aFont) = 0;

View File

@ -1108,32 +1108,32 @@ nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult)
}
NS_IMETHODIMP
nsPresContext::GetDefaultFont(PRUint8 aFontID, nsFont& aResult)
nsPresContext::GetDefaultFont(PRUint8 aFontID, const nsFont** aResult)
{
nsresult rv = NS_OK;
switch (aFontID) {
// Special (our default variable width font and fixed width font)
case kPresContext_DefaultVariableFont_ID:
aResult = mDefaultVariableFont;
*aResult = &mDefaultVariableFont;
break;
case kPresContext_DefaultFixedFont_ID:
aResult = mDefaultFixedFont;
*aResult = &mDefaultFixedFont;
break;
// CSS
case kGenericFont_serif:
aResult = mDefaultSerifFont;
*aResult = &mDefaultSerifFont;
break;
case kGenericFont_sans_serif:
aResult = mDefaultSansSerifFont;
*aResult = &mDefaultSansSerifFont;
break;
case kGenericFont_monospace:
aResult = mDefaultMonospaceFont;
*aResult = &mDefaultMonospaceFont;
break;
case kGenericFont_cursive:
aResult = mDefaultCursiveFont;
*aResult = &mDefaultCursiveFont;
break;
case kGenericFont_fantasy:
aResult = mDefaultFantasyFont;
*aResult = &mDefaultFantasyFont;
break;
default:
rv = NS_ERROR_INVALID_ARG;

View File

@ -109,7 +109,7 @@ public:
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult);
NS_IMETHOD AllocateFromShell(size_t aSize, void** aResult);
NS_IMETHOD FreeToShell(size_t aSize, void* aFreeChunk);
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, nsFont& aResult);
NS_IMETHOD GetDefaultFont(PRUint8 aFontID, const nsFont** aResult);
NS_IMETHOD SetDefaultFont(PRUint8 aFontID, const nsFont& aFont);
NS_IMETHOD GetCachedBoolPref(PRUint32 aPrefType, PRBool& aValue);
NS_IMETHOD GetCachedIntPref(PRUint32 aPrefType, PRInt32& aValue);

View File

@ -905,9 +905,9 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame,
const nsString& fontName = font->mFont.name;
PRUint8 generic = font->mFlags & NS_STYLE_FONT_FACE_MASK;
if (generic == kGenericFont_NONE) {
nsFont defaultFont;
presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
PRInt32 lendiff = fontName.Length() - defaultFont.name.Length();
const nsFont* defaultFont;
presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
PRInt32 lendiff = fontName.Length() - defaultFont->name.Length();
if (lendiff > 0) {
val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma
} else {

View File

@ -1589,9 +1589,9 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aConte
switch (aSID) {
case eStyleStruct_Font:
{
nsFont defaultFont;
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
nsStyleFont* fontData = new (mPresContext) nsStyleFont(defaultFont);
const nsFont* defaultFont;
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
nsStyleFont* fontData = new (mPresContext) nsStyleFont(*defaultFont);
aContext->SetStyle(eStyleStruct_Font, *fontData);
return fontData;
}
@ -1768,9 +1768,10 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
const nsFont& aDefaultFont, const nsStyleFont* aParentFont,
nsStyleFont* aFont, PRBool& aInherited)
{
nsFont defaultVariableFont, defaultFixedFont;
aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultVariableFont);
aPresContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, defaultFixedFont);
const nsFont* defaultVariableFont;
const nsFont* defaultFixedFont;
aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultVariableFont);
aPresContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, &defaultFixedFont);
// font-family: string list, enum, inherit
if (eCSSUnit_String == aFontData.mFamily.GetUnit()) {
@ -1832,9 +1833,9 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
aPresContext->GetDeviceContext(getter_AddRefs(dc));
if (dc) {
// GetSystemFont sets the font face but not necessarily the size
aFont->mFont.size = defaultVariableFont.size;
aFont->mFont.size = defaultVariableFont->size;
if (NS_FAILED(dc->GetSystemFont(sysID, &aFont->mFont))) {
aFont->mFont.name = defaultVariableFont.name;
aFont->mFont.name = defaultVariableFont->name;
}
aFont->mSize = aFont->mFont.size; // this becomes our cascading size
}
@ -1846,11 +1847,11 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
case eSystemFont_Field:
case eSystemFont_List:
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
break;
case eSystemFont_Button:
aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));
aFont->mSize = defaultVariableFont.size;
aFont->mSize = defaultVariableFont->size;
break;
}
}
@ -1878,10 +1879,10 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
case eSystemFont_Field:
if (eCompatibility_NavQuirks == mode) {
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
} else {
// Assumption: system defined font is proportional
aFont->mSize = PR_MAX(defaultVariableFont.size - NSIntPointsToTwips(2), 0);
aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);
}
break;
//
@ -1902,7 +1903,7 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
aFont->mFont.name.Assign(NS_LITERAL_STRING("sans-serif"));
}
// Assumption: system defined font is proportional
aFont->mSize = PR_MAX(defaultVariableFont.size - NSIntPointsToTwips(2), 0);
aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);
break;
}
#endif
@ -1912,12 +1913,12 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
switch (sysID) {
case eSystemFont_Field:
aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));
aFont->mSize = defaultFixedFont.size;
aFont->mSize = defaultFixedFont->size;
break;
case eSystemFont_Button:
case eSystemFont_List:
aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));
aFont->mSize = defaultVariableFont.size;
aFont->mSize = defaultVariableFont->size;
break;
default:
NS_ERROR("unexpected SID");
@ -2086,9 +2087,9 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
// If we stopped earlier because we reached the root of the style tree,
// we will start with the default generic font from the presentation
// context. Otherwise we start with the higher context.
nsFont defaultFont;
aPresContext->GetDefaultFont(aGenericFontID, defaultFont);
nsStyleFont parentFont(defaultFont);
const nsFont* defaultFont;
aPresContext->GetDefaultFont(aGenericFontID, &defaultFont);
nsStyleFont parentFont(*defaultFont);
PRInt32 i = contextPath.Count() - 1;
if (higherContext) {
nsIStyleContext* context = (nsIStyleContext*)contextPath[i];
@ -2134,7 +2135,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
SetFont(aPresContext, context, aMinFontSize,
aUseDocumentFonts, aChromeOverride, PR_TRUE,
fontData, defaultFont, &parentFont, aFont, dummy);
fontData, *defaultFont, &parentFont, aFont, dummy);
// XXX Not sure if we need to do this here
// If we have a post-resolve callback, handle that now.
@ -2151,7 +2152,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
// can just compute the delta from the parent.
SetFont(aPresContext, aContext, aMinFontSize,
aUseDocumentFonts, aChromeOverride, PR_TRUE,
aFontData, defaultFont, &parentFont, aFont, dummy);
aFontData, *defaultFont, &parentFont, aFont, dummy);
}
const nsStyleStruct*
@ -2187,10 +2188,10 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
}
}
nsFont defaultFont;
const nsFont* defaultFont;
if (!font) {
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, defaultFont);
font = new (mPresContext) nsStyleFont(defaultFont);
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
font = new (mPresContext) nsStyleFont(*defaultFont);
}
if (!parentFont)
parentFont = font;
@ -2256,10 +2257,10 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
// continue the normal processing
// our default font is the most recent generic font
generic = parentFont->mFlags & NS_STYLE_FONT_FACE_MASK;
mPresContext->GetDefaultFont(generic, defaultFont);
mPresContext->GetDefaultFont(generic, &defaultFont);
SetFont(mPresContext, aContext, minimumFontSize,
useDocumentFonts, chromeOverride, PR_FALSE,
fontData, defaultFont, parentFont, font, inherited);
fontData, *defaultFont, parentFont, font, inherited);
}
else {
// re-calculate the font as a generic font