Bug 1155836: Template on aComputeData in the DoGetStyle* helpers. r=dbaron f=bz

This commit is contained in:
David Major 2015-04-15 10:55:56 +12:00
Родитель 5844aafa2d
Коммит 8433a30b6f
3 изменённых файлов: 41 добавлений и 42 удалений

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

@ -9287,34 +9287,6 @@ nsRuleNode::GetStyleData(nsStyleStructID aSID,
return data;
}
// See comments above in GetStyleData for an explanation of what the
// code below does.
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_* \
nsRuleNode::GetStyle##name_(nsStyleContext* aContext, bool aComputeData) \
{ \
NS_ASSERTION(IsUsedDirectly(), \
"if we ever call this on rule nodes that aren't used " \
"directly, we should adjust handling of mDependentBits " \
"in some way."); \
\
const nsStyle##name_ *data; \
data = mStyleData.GetStyle##name_(); \
if (MOZ_LIKELY(data != nullptr)) \
return data; \
\
if (MOZ_UNLIKELY(!aComputeData)) \
return nullptr; \
\
data = static_cast<const nsStyle##name_ *> \
(WalkRuleTree(eStyleStruct_##name_, aContext)); \
\
MOZ_ASSERT(data, "should have aborted on out-of-memory"); \
return data; \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
void
nsRuleNode::Mark()
{

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

@ -715,9 +715,33 @@ public:
nsStyleContext* aContext,
bool aComputeData);
// See comments in GetStyleData for an explanation of what the
// code below does.
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_* GetStyle##name_(nsStyleContext* aContext, \
bool aComputeData);
template<bool aComputeData> \
const nsStyle##name_* \
GetStyle##name_(nsStyleContext* aContext) \
{ \
NS_ASSERTION(IsUsedDirectly(), \
"if we ever call this on rule nodes that aren't used " \
"directly, we should adjust handling of mDependentBits " \
"in some way."); \
\
const nsStyle##name_ *data; \
data = mStyleData.GetStyle##name_(); \
if (MOZ_LIKELY(data != nullptr)) \
return data; \
\
if (!aComputeData) \
return nullptr; \
\
data = static_cast<const nsStyle##name_ *> \
(WalkRuleTree(eStyleStruct_##name_, aContext)); \
\
MOZ_ASSERT(data, "should have aborted on out-of-memory"); \
return data; \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT

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

@ -323,7 +323,7 @@ public:
*/
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_ * Style##name_() { \
return DoGetStyle##name_(true); \
return DoGetStyle##name_<true>(); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
@ -337,7 +337,7 @@ public:
*/
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_ * PeekStyle##name_() { \
return DoGetStyle##name_(false); \
return DoGetStyle##name_<false>(); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
@ -502,7 +502,8 @@ private:
// Helper functions for GetStyle* and PeekStyle*
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
const nsStyle##name_ * DoGetStyle##name_(bool aComputeData) { \
template<bool aComputeData> \
const nsStyle##name_ * DoGetStyle##name_() { \
const nsStyle##name_ * cachedData = \
static_cast<nsStyle##name_*>( \
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]); \
@ -510,19 +511,21 @@ private:
return cachedData; \
/* Have the rulenode deal */ \
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
return mRuleNode->GetStyle##name_(this, aComputeData); \
return mRuleNode->GetStyle##name_<aComputeData>(this); \
}
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
const nsStyle##name_ * DoGetStyle##name_(bool aComputeData) { \
const nsStyle##name_ * cachedData = mCachedResetData \
? static_cast<nsStyle##name_*>( \
mCachedResetData->mStyleStructs[eStyleStruct_##name_]) \
: nullptr; \
if (cachedData) /* Have it cached already, yay */ \
return cachedData; \
template<bool aComputeData> \
const nsStyle##name_ * DoGetStyle##name_() { \
if (mCachedResetData) { \
const nsStyle##name_ * cachedData = \
static_cast<nsStyle##name_*>( \
mCachedResetData->mStyleStructs[eStyleStruct_##name_]); \
if (cachedData) /* Have it cached already, yay */ \
return cachedData; \
} \
/* Have the rulenode deal */ \
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
return mRuleNode->GetStyle##name_(this, aComputeData); \
return mRuleNode->GetStyle##name_<aComputeData>(this); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT_RESET