Convert jump tables to if-else trees to avoid the performance cost of function pointers. b=210550 r+sr=bzbarsky

This commit is contained in:
dbaron%dbaron.org 2003-07-09 03:46:27 +00:00
Родитель aef373ce51
Коммит 35a6c43f33
6 изменённых файлов: 154 добавлений и 88 удалений

Просмотреть файл

@ -1409,9 +1409,14 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID,
}
// We need to compute the data from the information that the rules specified.
ComputeStyleDataFn fn = gComputeStyleDataFn[aSID];
const nsStyleStruct* res = (this->*fn)(startStruct, *aSpecificData, aContext, highestNode, detail,
!aRuleData->mCanStoreInRuleTree);
const nsStyleStruct* res;
#define STYLE_STRUCT_TEST aSID
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
res = Compute##name##Data(startStruct, *aSpecificData, aContext, \
highestNode, detail, !aRuleData->mCanStoreInRuleTree);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_TEST
// If we have a post-resolve callback, handle that now.
if (aRuleData->mPostResolveCallback)
@ -1587,17 +1592,6 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex
return nsnull;
}
nsRuleNode::ComputeStyleDataFn
nsRuleNode::gComputeStyleDataFn[] = {
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
&nsRuleNode::Compute##name##Data,
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
nsnull
};
static void
SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext,
nscoord aMinFontSize, PRBool aUseDocumentFonts, PRBool aChromeOverride,
@ -4366,17 +4360,6 @@ nsRuleNode::GetParentData(const nsStyleStructID aSID)
return nsnull;
}
nsRuleNode::GetStyleDataFn
nsRuleNode::gGetStyleDataFn[] = {
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
&nsRuleNode::Get##name##Data,
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
nsnull
};
const nsStyleStruct*
nsRuleNode::GetStyleData(nsStyleStructID aSID,
nsStyleContext* aContext,
@ -4400,12 +4383,13 @@ nsRuleNode::GetStyleData(nsStyleStructID aSID,
return nsnull;
// Nothing is cached. We'll have to delve further and examine our rules.
GetStyleDataFn fn = gGetStyleDataFn[aSID];
if (!fn) {
NS_NOTREACHED("unknown style struct requested");
return nsnull;
}
data = (this->*fn)(aContext);
#define STYLE_STRUCT_TEST aSID
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
data = Get##name##Data(aContext);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_TEST
if (data)
return data;

Просмотреть файл

@ -490,16 +490,6 @@ protected:
const RuleDetail& aRuleDetail, PRBool aInherited);
#endif
typedef const nsStyleStruct*
(nsRuleNode::*ComputeStyleDataFn)(nsStyleStruct* aStartStruct,
const nsRuleDataStruct& aStartData,
nsStyleContext* aContext,
nsRuleNode* aHighestNode,
const RuleDetail& aRuleDetail,
PRBool aInherited);
static ComputeStyleDataFn gComputeStyleDataFn[];
inline RuleDetail CheckSpecifiedProperties(const nsStyleStructID aSID, const nsRuleDataStruct& aRuleDataStruct);
const nsStyleStruct* GetParentData(const nsStyleStructID aSID);
@ -527,9 +517,6 @@ protected:
const nsStyleStruct* GetSVGData(nsStyleContext* aContext);
#endif
typedef const nsStyleStruct* (nsRuleNode::*GetStyleDataFn)(nsStyleContext*);
static GetStyleDataFn gGetStyleDataFn[];
public:
nsRuleNode(nsIPresContext* aPresContext, nsIStyleRule* aRule,
nsRuleNode* aParent);

Просмотреть файл

@ -55,29 +55,89 @@
#define UNDEF_STYLE_STRUCT_RESET
#endif
#ifdef STYLE_STRUCT_TEST
#define STYLE_STRUCT_TEST_CODE(c) c
#else
#define STYLE_STRUCT_TEST_CODE(c)
#endif
STYLE_STRUCT_TEST_CODE(if (STYLE_STRUCT_TEST < 8) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 4) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 2) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 0) {)
STYLE_STRUCT_INHERITED(Font, CheckFontCallback, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(Color, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 2) {)
STYLE_STRUCT_RESET(Background, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(List, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 6) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 4) {)
STYLE_STRUCT_RESET(Position, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(Text, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 6) {)
STYLE_STRUCT_RESET(TextReset, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Display, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(} else if (STYLE_STRUCT_TEST < 16) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 12) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 10) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 8) {)
STYLE_STRUCT_INHERITED(Visibility, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Content, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 10) {)
STYLE_STRUCT_INHERITED(Quotes, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(UserInterface, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 14) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 12) {)
STYLE_STRUCT_RESET(UIReset, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Table, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 14) {)
STYLE_STRUCT_INHERITED(TableBorder, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Margin, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(} else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 18) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 16) {)
STYLE_STRUCT_RESET(Padding, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Border, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 18) {)
STYLE_STRUCT_RESET(Outline, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 19) {)
STYLE_STRUCT_RESET(XUL, nsnull, ())
#ifdef MOZ_SVG
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 20) {)
STYLE_STRUCT_INHERITED(SVG, nsnull, ())
#endif
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(})
#ifdef UNDEF_STYLE_STRUCT_INHERITED
#undef STYLE_STRUCT_INHERITED
@ -88,3 +148,5 @@ STYLE_STRUCT_INHERITED(SVG, nsnull, ())
#undef STYLE_STRUCT_RESET
#undef UNDEF_STYLE_STRUCT_RESET
#endif
#undef STYLE_STRUCT_TEST_CODE

Просмотреть файл

@ -1409,9 +1409,14 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID,
}
// We need to compute the data from the information that the rules specified.
ComputeStyleDataFn fn = gComputeStyleDataFn[aSID];
const nsStyleStruct* res = (this->*fn)(startStruct, *aSpecificData, aContext, highestNode, detail,
!aRuleData->mCanStoreInRuleTree);
const nsStyleStruct* res;
#define STYLE_STRUCT_TEST aSID
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
res = Compute##name##Data(startStruct, *aSpecificData, aContext, \
highestNode, detail, !aRuleData->mCanStoreInRuleTree);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_TEST
// If we have a post-resolve callback, handle that now.
if (aRuleData->mPostResolveCallback)
@ -1587,17 +1592,6 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex
return nsnull;
}
nsRuleNode::ComputeStyleDataFn
nsRuleNode::gComputeStyleDataFn[] = {
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
&nsRuleNode::Compute##name##Data,
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
nsnull
};
static void
SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext,
nscoord aMinFontSize, PRBool aUseDocumentFonts, PRBool aChromeOverride,
@ -4366,17 +4360,6 @@ nsRuleNode::GetParentData(const nsStyleStructID aSID)
return nsnull;
}
nsRuleNode::GetStyleDataFn
nsRuleNode::gGetStyleDataFn[] = {
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
&nsRuleNode::Get##name##Data,
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
nsnull
};
const nsStyleStruct*
nsRuleNode::GetStyleData(nsStyleStructID aSID,
nsStyleContext* aContext,
@ -4400,12 +4383,13 @@ nsRuleNode::GetStyleData(nsStyleStructID aSID,
return nsnull;
// Nothing is cached. We'll have to delve further and examine our rules.
GetStyleDataFn fn = gGetStyleDataFn[aSID];
if (!fn) {
NS_NOTREACHED("unknown style struct requested");
return nsnull;
}
data = (this->*fn)(aContext);
#define STYLE_STRUCT_TEST aSID
#define STYLE_STRUCT(name, checkdata_cb, ctor_args) \
data = Get##name##Data(aContext);
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_TEST
if (data)
return data;

Просмотреть файл

@ -490,16 +490,6 @@ protected:
const RuleDetail& aRuleDetail, PRBool aInherited);
#endif
typedef const nsStyleStruct*
(nsRuleNode::*ComputeStyleDataFn)(nsStyleStruct* aStartStruct,
const nsRuleDataStruct& aStartData,
nsStyleContext* aContext,
nsRuleNode* aHighestNode,
const RuleDetail& aRuleDetail,
PRBool aInherited);
static ComputeStyleDataFn gComputeStyleDataFn[];
inline RuleDetail CheckSpecifiedProperties(const nsStyleStructID aSID, const nsRuleDataStruct& aRuleDataStruct);
const nsStyleStruct* GetParentData(const nsStyleStructID aSID);
@ -527,9 +517,6 @@ protected:
const nsStyleStruct* GetSVGData(nsStyleContext* aContext);
#endif
typedef const nsStyleStruct* (nsRuleNode::*GetStyleDataFn)(nsStyleContext*);
static GetStyleDataFn gGetStyleDataFn[];
public:
nsRuleNode(nsIPresContext* aPresContext, nsIStyleRule* aRule,
nsRuleNode* aParent);

Просмотреть файл

@ -55,29 +55,89 @@
#define UNDEF_STYLE_STRUCT_RESET
#endif
#ifdef STYLE_STRUCT_TEST
#define STYLE_STRUCT_TEST_CODE(c) c
#else
#define STYLE_STRUCT_TEST_CODE(c)
#endif
STYLE_STRUCT_TEST_CODE(if (STYLE_STRUCT_TEST < 8) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 4) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 2) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 0) {)
STYLE_STRUCT_INHERITED(Font, CheckFontCallback, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(Color, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 2) {)
STYLE_STRUCT_RESET(Background, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(List, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 6) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 4) {)
STYLE_STRUCT_RESET(Position, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(Text, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 6) {)
STYLE_STRUCT_RESET(TextReset, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Display, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(} else if (STYLE_STRUCT_TEST < 16) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 12) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 10) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 8) {)
STYLE_STRUCT_INHERITED(Visibility, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Content, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 10) {)
STYLE_STRUCT_INHERITED(Quotes, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_INHERITED(UserInterface, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 14) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 12) {)
STYLE_STRUCT_RESET(UIReset, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Table, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 14) {)
STYLE_STRUCT_INHERITED(TableBorder, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Margin, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(} else {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST < 18) {)
STYLE_STRUCT_TEST_CODE( if (STYLE_STRUCT_TEST == 16) {)
STYLE_STRUCT_RESET(Padding, nsnull, ())
STYLE_STRUCT_TEST_CODE( } else {)
STYLE_STRUCT_RESET(Border, nsnull, ())
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 18) {)
STYLE_STRUCT_RESET(Outline, nsnull, (SSARG_PRESCONTEXT))
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 19) {)
STYLE_STRUCT_RESET(XUL, nsnull, ())
#ifdef MOZ_SVG
STYLE_STRUCT_TEST_CODE( } else if (STYLE_STRUCT_TEST == 20) {)
STYLE_STRUCT_INHERITED(SVG, nsnull, ())
#endif
STYLE_STRUCT_TEST_CODE( })
STYLE_STRUCT_TEST_CODE(})
#ifdef UNDEF_STYLE_STRUCT_INHERITED
#undef STYLE_STRUCT_INHERITED
@ -88,3 +148,5 @@ STYLE_STRUCT_INHERITED(SVG, nsnull, ())
#undef STYLE_STRUCT_RESET
#undef UNDEF_STYLE_STRUCT_RESET
#endif
#undef STYLE_STRUCT_TEST_CODE