Bug 591303 - Part 1: Move mLineNumber, mColumnNumber, and mWasMatched from StyleRule to Rule. r=bz
authorGabriel Luong <gabriel.luong@gmail.com>
Mon, 14 Jul 2014 15:57:02 -0700
changeset 214743 89311542468d3f9269cfe25e4adc68af54dbc00c
parent 214742 734231b3e382a9453118ab27612dfb5e3859531d
child 214744 785257a95e363df9238b4ffc7fdc78eabe1b2369
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs591303
milestone33.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
Bug 591303 - Part 1: Move mLineNumber, mColumnNumber, and mWasMatched from StyleRule to Rule. r=bz Also, pass the line/column number through the constructor rather than through a separate function.
layout/style/Rule.h
layout/style/StyleRule.cpp
layout/style/StyleRule.h
layout/style/nsCSSParser.cpp
--- a/layout/style/Rule.h
+++ b/layout/style/Rule.h
@@ -28,25 +28,31 @@ virtual void MapRuleInfoInto(nsRuleData*
 
 #define DECL_STYLE_RULE_INHERIT                   \
   DECL_STYLE_RULE_INHERIT_NO_DOMRULE              \
   virtual nsIDOMCSSRule* GetDOMRule();            \
   virtual nsIDOMCSSRule* GetExistingDOMRule();
 
 class Rule : public nsIStyleRule {
 protected:
-  Rule()
+  Rule(uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0)
     : mSheet(0),
-      mParentRule(nullptr)
+      mParentRule(nullptr),
+      mLineNumber(aLineNumber),
+      mColumnNumber(aColumnNumber),
+      mWasMatched(false)
   {
   }
 
   Rule(const Rule& aCopy)
     : mSheet(aCopy.mSheet),
-      mParentRule(aCopy.mParentRule)
+      mParentRule(aCopy.mParentRule),
+      mLineNumber(aCopy.mLineNumber),
+      mColumnNumber(aCopy.mColumnNumber),
+      mWasMatched(false)
   {
   }
 
   virtual ~Rule() {}
 
 public:
 
   // The constants in this list must maintain the following invariants:
@@ -90,16 +96,19 @@ public:
 
   void SetParentRule(GroupRule* aRule) {
     // We don't reference count this up reference. The group rule
     // will tell us when it's going away or when we're detached from
     // it.
     mParentRule = aRule;
   }
 
+  uint32_t GetLineNumber() const { return mLineNumber; }
+  uint32_t GetColumnNumber() const { return mColumnNumber; }
+
   /**
    * Clones |this|. Never returns nullptr.
    */
   virtual already_AddRefed<Rule> Clone() const = 0;
 
   // Note that this returns null for inline style rules since they aren't
   // supposed to have a DOM rule representation (and our code wouldn't work).
   virtual nsIDOMCSSRule* GetDOMRule() = 0;
@@ -121,14 +130,19 @@ public:
                                                    mozilla::MallocSizeOf aMallocSizeOf,
                                                    void* aData);
 
 protected:
   // This is either a CSSStyleSheet* or an nsHTMLStyleSheet*.  The former
   // if the low bit is 0, the latter if the low bit is 1.
   uintptr_t         mSheet;
   GroupRule*        mParentRule;
+
+  // Keep the same type so that MSVC packs them.
+  uint32_t          mLineNumber;
+  uint32_t          mColumnNumber : 31;
+  uint32_t          mWasMatched : 1;
 };
 
 } // namespace css
 } // namespace mozilla
 
 #endif /* mozilla_css_Rule_h___ */
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -1298,49 +1298,42 @@ DOMCSSStyleRule::GetCSSStyleRule(StyleRu
 } // namespace mozilla
 
 // -- StyleRule ------------------------------------
 
 namespace mozilla {
 namespace css {
 
 StyleRule::StyleRule(nsCSSSelectorList* aSelector,
-                     Declaration* aDeclaration)
-  : Rule(),
+                     Declaration* aDeclaration,
+                     uint32_t aLineNumber,
+                     uint32_t aColumnNumber)
+  : Rule(aLineNumber, aColumnNumber),
     mSelector(aSelector),
-    mDeclaration(aDeclaration),
-    mLineNumber(0),
-    mColumnNumber(0),
-    mWasMatched(false)
+    mDeclaration(aDeclaration)
 {
   NS_PRECONDITION(aDeclaration, "must have a declaration");
 }
 
 // for |Clone|
 StyleRule::StyleRule(const StyleRule& aCopy)
   : Rule(aCopy),
     mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr),
-    mDeclaration(new Declaration(*aCopy.mDeclaration)),
-    mLineNumber(aCopy.mLineNumber),
-    mColumnNumber(aCopy.mColumnNumber),
-    mWasMatched(false)
+    mDeclaration(new Declaration(*aCopy.mDeclaration))
 {
   // rest is constructed lazily on existing data
 }
 
 // for |SetCSSDeclaration|
 StyleRule::StyleRule(StyleRule& aCopy,
                      Declaration* aDeclaration)
   : Rule(aCopy),
     mSelector(aCopy.mSelector),
     mDeclaration(aDeclaration),
-    mDOMRule(aCopy.mDOMRule.forget()),
-    mLineNumber(aCopy.mLineNumber),
-    mColumnNumber(aCopy.mColumnNumber),
-    mWasMatched(false)
+    mDOMRule(aCopy.mDOMRule.forget())
 {
   // The DOM rule is replacing |aCopy| with |this|, so transfer
   // the reverse pointer as well (and transfer ownership).
 
   // Similarly for the selector.
   aCopy.mSelector = nullptr;
 
   // We are probably replacing the old declaration with |aDeclaration|
--- a/layout/style/StyleRule.h
+++ b/layout/style/StyleRule.h
@@ -297,37 +297,32 @@ protected:
 
   friend class StyleRule;
 };
 
 class StyleRule MOZ_FINAL : public Rule
 {
  public:
   StyleRule(nsCSSSelectorList* aSelector,
-            Declaration *aDeclaration);
+            Declaration *aDeclaration,
+            uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
 private:
   // for |Clone|
   StyleRule(const StyleRule& aCopy);
   // for |DeclarationChanged|
   StyleRule(StyleRule& aCopy,
             Declaration *aDeclaration);
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID)
 
   NS_DECL_ISUPPORTS
 
   // null for style attribute
   nsCSSSelectorList* Selector() { return mSelector; }
 
-  uint32_t GetLineNumber() const { return mLineNumber; }
-  uint32_t GetColumnNumber() const { return mColumnNumber; }
-  void SetLineNumberAndColumnNumber(uint32_t aLineNumber,
-                                    uint32_t aColumnNumber)
-  { mLineNumber = aLineNumber; mColumnNumber = aColumnNumber; }
-
   Declaration* GetDeclaration() const { return mDeclaration; }
 
   /**
    * Return a new |nsIStyleRule| instance that replaces the current
    * one, with |aDecl| replacing the previous declaration. Due to the
    * |nsIStyleRule| contract of immutability, this must be called if
    * the declaration is modified.
    *
@@ -371,20 +366,16 @@ public:
 private:
   ~StyleRule();
 
 private:
   nsCSSSelectorList*      mSelector; // null for style attribute
   Declaration*            mDeclaration;
   nsRefPtr<ImportantRule> mImportantRule; // initialized by RuleMatched
   nsRefPtr<DOMCSSStyleRule> mDOMRule;
-  // Keep the same type so that MSVC packs them.
-  uint32_t                mLineNumber;
-  uint32_t                mColumnNumber : 31;
-  uint32_t                mWasMatched : 1;
 
 private:
   StyleRule& operator=(const StyleRule& aCopy) MOZ_DELETE;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(StyleRule, NS_CSS_STYLE_RULE_IMPL_CID)
 
 } // namespace css
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -4721,18 +4721,18 @@ CSSParserImpl::ParseRuleSet(RuleAppendFu
   slist->Dump();
   fputs("{\n", stdout);
   declaration->List();
   fputs("}\n", stdout);
 #endif
 
   // Translate the selector list and declaration block into style data
 
-  nsRefPtr<css::StyleRule> rule = new css::StyleRule(slist, declaration);
-  rule->SetLineNumberAndColumnNumber(linenum, colnum);
+  nsRefPtr<css::StyleRule> rule = new css::StyleRule(slist, declaration,
+                                                     linenum, colnum);
   (*aAppendFunc)(rule, aData);
 
   return true;
 }
 
 bool
 CSSParserImpl::ParseSelectorList(nsCSSSelectorList*& aListHead,
                                  char16_t aStopChar)