From 8433a30b6f6ed71460e8a49784d39f31932f93ad Mon Sep 17 00:00:00 2001 From: David Major Date: Wed, 15 Apr 2015 10:55:56 +1200 Subject: [PATCH] Bug 1155836: Template on aComputeData in the DoGetStyle* helpers. r=dbaron f=bz --- layout/style/nsRuleNode.cpp | 28 ---------------------------- layout/style/nsRuleNode.h | 28 ++++++++++++++++++++++++++-- layout/style/nsStyleContext.h | 27 +++++++++++++++------------ 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 407fc93edd64..24a47553a280 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -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 \ - (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() { diff --git a/layout/style/nsRuleNode.h b/layout/style/nsRuleNode.h index 9cb38eabdaf0..c651757f654f 100644 --- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -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 \ + 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 \ + (WalkRuleTree(eStyleStruct_##name_, aContext)); \ + \ + MOZ_ASSERT(data, "should have aborted on out-of-memory"); \ + return data; \ + } #include "nsStyleStructList.h" #undef STYLE_STRUCT diff --git a/layout/style/nsStyleContext.h b/layout/style/nsStyleContext.h index 33ba5699a3a1..16bfc528bf16 100644 --- a/layout/style/nsStyleContext.h +++ b/layout/style/nsStyleContext.h @@ -323,7 +323,7 @@ public: */ #define STYLE_STRUCT(name_, checkdata_cb_) \ const nsStyle##name_ * Style##name_() { \ - return DoGetStyle##name_(true); \ + return DoGetStyle##name_(); \ } #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_(); \ } #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 \ + const nsStyle##name_ * DoGetStyle##name_() { \ const nsStyle##name_ * cachedData = \ static_cast( \ 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_(this); \ } #define STYLE_STRUCT_RESET(name_, checkdata_cb_) \ - const nsStyle##name_ * DoGetStyle##name_(bool aComputeData) { \ - const nsStyle##name_ * cachedData = mCachedResetData \ - ? static_cast( \ - mCachedResetData->mStyleStructs[eStyleStruct_##name_]) \ - : nullptr; \ - if (cachedData) /* Have it cached already, yay */ \ - return cachedData; \ + template \ + const nsStyle##name_ * DoGetStyle##name_() { \ + if (mCachedResetData) { \ + const nsStyle##name_ * cachedData = \ + static_cast( \ + 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_(this); \ } #include "nsStyleStructList.h" #undef STYLE_STRUCT_RESET