author | David Major <dmajor@mozilla.com> |
Wed, 15 Apr 2015 10:55:56 +1200 | |
changeset 241888 | 98d3519ab098ebb3bb7ed3ceb405812e3d8b75de |
parent 241887 | 4d85a02e9c286a64c47d21e8f1f12d7fbbeb4c5e |
child 241889 | b318ff4e610e6355d87fc97a6ad90e7b2f26c94e |
push id | 28672 |
push user | ryanvm@gmail.com |
push date | Fri, 01 May 2015 16:57:20 +0000 |
treeherder | mozilla-central@e70555ac58d8 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dbaron |
bugs | 1155836 |
milestone | 40.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -9282,44 +9282,16 @@ nsRuleNode::GetStyleData(nsStyleStructID // Nothing is cached. We'll have to delve further and examine our rules. data = WalkRuleTree(aSID, aContext); MOZ_ASSERT(data, "should have aborted on out-of-memory"); 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() { for (nsRuleNode *node = this; node && !(node->mDependentBits & NS_RULE_NODE_GC_MARK); node = node->mParent) node->mDependentBits |= NS_RULE_NODE_GC_MARK; }
--- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -710,19 +710,43 @@ public: nsIStyleRule* GetRule() const { return mRule; } // NOTE: Does not |AddRef|. Never null. nsPresContext* PresContext() const { return mPresContext; } const void* GetStyleData(nsStyleStructID aSID, 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 /* * Garbage collection. Mark walks up the tree, marking any unmarked * ancestors until it reaches a marked one. Sweep recursively sweeps * the children, destroys any that are unmarked, and clears marks, * returning true if the node on which it was called was destroyed.
--- a/layout/style/nsStyleContext.h +++ b/layout/style/nsStyleContext.h @@ -318,31 +318,31 @@ public: * Define typesafe getter functions for each style struct by * preprocessing the list of style structs. These functions are the * preferred way to get style data. The macro creates functions like: * const nsStyleBorder* StyleBorder(); * const nsStyleColor* StyleColor(); */ #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 /** * PeekStyle* is like GetStyle* but doesn't trigger style * computation if the data is not cached on either the style context * or the rule node. * * Perhaps this shouldn't be a public nsStyleContext API. */ #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 /** * Compute the style changes needed during restyling when this style * context is being replaced by aOther. (This is nonsymmetric since * we optimize by skipping comparison for styles that have never been @@ -497,37 +497,40 @@ private: #define AUTO_CHECK_DEPENDENCY(sid_) \ AutoCheckDependency checkNesting_(this, sid_) #else #define AUTO_CHECK_DEPENDENCY(sid_) #endif // 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_]); \ 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); \ } #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 #undef STYLE_STRUCT_INHERITED // Helper for ClearCachedInheritedStyleDataOnDescendants. void DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);