Bug 569719 part 4: Move nsCSSExpandedDataBlock::RuleDataPropertyAt into struct nsRuleData. r=dbaron
authorZack Weinberg <zweinberg@mozilla.com>
Fri, 23 Jul 2010 11:00:21 -0700
changeset 48852 cf6990d475299e59d4c71d28414624392ff1efad
parent 48851 9c9fba3c49a639b9ab2c2a62bf743f6672953392
child 48853 ae6c685d5a378f82eb4c8caf5eafe30e35fdfc1c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs569719
milestone2.0b4pre
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 569719 part 4: Move nsCSSExpandedDataBlock::RuleDataPropertyAt into struct nsRuleData. r=dbaron
layout/style/Makefile.in
layout/style/nsCSSDataBlock.cpp
layout/style/nsCSSDataBlock.h
layout/style/nsRuleData.cpp
layout/style/nsRuleData.h
layout/style/nsTransitionManager.cpp
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -131,16 +131,17 @@ CPPSRCS		= \
 		nsDOMCSSRect.cpp \
 		nsDOMCSSValueList.cpp \
 		nsFontFaceLoader.cpp \
 		nsHTMLCSSStyleSheet.cpp \
 		nsHTMLStyleSheet.cpp \
 		nsLayoutStylesheetCache.cpp \
 		nsMediaFeatures.cpp \
 		nsROCSSPrimitiveValue.cpp \
+		nsRuleData.cpp \
 		nsRuleNode.cpp \
 		nsStyleAnimation.cpp \
 		nsStyleContext.cpp \
 		nsStyleCoord.cpp \
 		nsStyleSet.cpp \
 		nsStyleStruct.cpp \
 		nsStyleTransformMatrix.cpp \
 		nsStyleUtil.cpp \
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -233,18 +233,17 @@ nsCSSCompressedDataBlock::MapRuleInfoInt
     const char* cursor = Block();
     const char* cursor_end = BlockEnd();
     while (cursor < cursor_end) {
         nsCSSProperty iProp = PropertyAtCursor(cursor);
         NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                      "out of range");
         if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
             aRuleData->mSIDs) {
-            void *prop =
-                nsCSSExpandedDataBlock::RuleDataPropertyAt(aRuleData, iProp);
+            void *prop = aRuleData->StorageFor(iProp);
             switch (nsCSSProps::kTypeTable[iProp]) {
                 case eCSSType_Value: {
                     nsCSSValue* target = static_cast<nsCSSValue*>(prop);
                     if (target->GetUnit() == eCSSUnit_Null) {
                         const nsCSSValue *val = ValueAtCursor(cursor);
                         NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
                         if (ShouldStartImageLoads(aRuleData, iProp)) {
                             TryToStartImageLoad(*val, doc, iProp);
@@ -576,31 +575,23 @@ nsCSSExpandedDataBlock::nsCSSExpandedDat
     AssertInitialState();
 }
 
 nsCSSExpandedDataBlock::~nsCSSExpandedDataBlock()
 {
     AssertInitialState();
 }
 
-const nsCSSExpandedDataBlock::PropertyOffsetInfo
-nsCSSExpandedDataBlock::kOffsetTable[eCSSProperty_COUNT_no_shorthands] = {
-    #define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, datastruct_,     \
-                                 member_, type_, kwtable_)                     \
-        { offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_),            \
-          size_t(-1),                                                          \
-          size_t(-1) },
+const size_t
+nsCSSExpandedDataBlock::kOffsetTable[] = {
     #define CSS_PROP(name_, id_, method_, flags_, datastruct_, member_, type_, \
                      kwtable_, stylestruct_, stylestructoffset_, animtype_)    \
-        { offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_),            \
-          offsetof(nsRuleData, m##datastruct_##Data),                          \
-          offsetof(nsRuleData##datastruct_, member_) },
+        offsetof(nsCSSExpandedDataBlock, m##datastruct_.member_),
     #include "nsCSSPropList.h"
     #undef CSS_PROP
-    #undef CSS_PROP_BACKENDONLY
 };
 
 void
 nsCSSExpandedDataBlock::DoExpand(nsRefPtr<nsCSSCompressedDataBlock> *aBlock,
                                  PRBool aImportant)
 {
     NS_PRECONDITION(*aBlock, "unexpected null block");
 
--- a/layout/style/nsCSSDataBlock.h
+++ b/layout/style/nsCSSDataBlock.h
@@ -273,25 +273,19 @@ private:
 
     void DoExpand(nsRefPtr<nsCSSCompressedDataBlock> *aBlock,
                   PRBool aImportant);
 
 #ifdef DEBUG
     void DoAssertInitialState();
 #endif
 
-    struct PropertyOffsetInfo {
-        // XXX These could probably be pointer-to-member, if the casting can
-        // be done correctly.
-        size_t block_offset; // offset of value in nsCSSExpandedDataBlock
-        size_t ruledata_struct_offset; // offset of nsRuleData* in nsRuleData
-        size_t ruledata_member_offset; // offset of value in nsRuleData*
-    };
-
-    static const PropertyOffsetInfo kOffsetTable[];
+    // XXX These could probably be pointer-to-member, if the casting can
+    // be done correctly.
+    static const size_t kOffsetTable[];
 
     /*
      * mPropertiesSet stores a bit for every property that is present,
      * to optimize compression of blocks with small numbers of
      * properties (the norm) and to allow quickly checking whether a
      * property is set in this block.
      */
     nsCSSPropertySet mPropertiesSet;
@@ -302,38 +296,18 @@ private:
 
 public:
     /*
      * Return the storage location within |this| of the value of the
      * property (i.e., either an |nsCSSValue*|, |nsCSSRect*|, or
      * |nsCSSValueList**| (etc.).
      */
     void* PropertyAt(nsCSSProperty aProperty) {
-        const PropertyOffsetInfo& offsets =
-            nsCSSExpandedDataBlock::kOffsetTable[aProperty];
-        return reinterpret_cast<void*>(reinterpret_cast<char*>(this) +
-                                          offsets.block_offset);
-    }
-
-    /*
-     * Return the storage location within |aRuleData| of the value of
-     * the property (i.e., either an |nsCSSValue*|, |nsCSSRect*|, or
-     * |nsCSSValueList**| (etc.).
-     */
-    static void* RuleDataPropertyAt(nsRuleData *aRuleData,
-                                    nsCSSProperty aProperty) {
-        const PropertyOffsetInfo& offsets =
-            nsCSSExpandedDataBlock::kOffsetTable[aProperty];
-        NS_ASSERTION(offsets.ruledata_struct_offset != size_t(-1),
-                     "property should not use CSS_PROP_BACKENDONLY");
-        char* cssstruct = *reinterpret_cast<char**>
-                                           (reinterpret_cast<char*>(aRuleData) +
-                              offsets.ruledata_struct_offset);
-        return reinterpret_cast<void*>
-                               (cssstruct + offsets.ruledata_member_offset);
+        size_t offset = nsCSSExpandedDataBlock::kOffsetTable[aProperty];
+        return reinterpret_cast<void*>(reinterpret_cast<char*>(this) + offset);
     }
 
     void SetPropertyBit(nsCSSProperty aProperty) {
         mPropertiesSet.AddProperty(aProperty);
     }
 
     void ClearPropertyBit(nsCSSProperty aProperty) {
         mPropertiesSet.RemoveProperty(aProperty);
new file mode 100644
--- /dev/null
+++ b/layout/style/nsRuleData.cpp
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Original Author: David W. Hyatt (hyatt@netscape.com)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsRuleData.h"
+#include "nsCSSProps.h"
+
+namespace {
+
+struct PropertyOffsetInfo {
+  // XXX These could probably be pointer-to-member, if the casting can
+  // be done correctly.
+  size_t struct_offset; // offset of nsRuleDataThing* in nsRuleData
+  size_t member_offset; // offset of value in nsRuleDataThing
+};
+
+const PropertyOffsetInfo kOffsetTable[eCSSProperty_COUNT_no_shorthands] = {
+  #define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, datastruct_,     \
+                               member_, type_, kwtable_)                     \
+      { size_t(-1), size_t(-1) },
+  #define CSS_PROP(name_, id_, method_, flags_, datastruct_, member_, type_, \
+                   kwtable_, stylestruct_, stylestructoffset_, animtype_)    \
+      { offsetof(nsRuleData, m##datastruct_##Data),                          \
+        offsetof(nsRuleData##datastruct_, member_) },
+  #include "nsCSSPropList.h"
+  #undef CSS_PROP
+  #undef CSS_PROP_BACKENDONLY
+};
+
+} // anon namespace
+
+void*
+nsRuleData::StorageFor(nsCSSProperty aProperty)
+{
+  NS_ABORT_IF_FALSE(aProperty < eCSSProperty_COUNT_no_shorthands,
+                    "invalid or shorthand property");
+
+  const PropertyOffsetInfo& offsets = kOffsetTable[aProperty];
+  NS_ABORT_IF_FALSE(offsets.struct_offset != size_t(-1),
+                    "backend-only property");
+
+  char* cssstruct = *reinterpret_cast<char**>
+    (reinterpret_cast<char*>(this) + offsets.struct_offset);
+  NS_ABORT_IF_FALSE(cssstruct, "substructure pointer should never be null");
+
+  return reinterpret_cast<void*>(cssstruct + offsets.member_offset);
+}
--- a/layout/style/nsRuleData.h
+++ b/layout/style/nsRuleData.h
@@ -33,58 +33,81 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * temporary (expanded) representation of property-value pairs used to
- * hold data from matched rules during style data computation 
+ * hold data from matched rules during style data computation.
  */
 
 #ifndef nsRuleData_h_
 #define nsRuleData_h_
 
+#include "nsCSSProps.h"
 #include "nsCSSStruct.h"
 #include "nsStyleStructFwd.h"
+
 class nsPresContext;
 class nsStyleContext;
+struct nsRuleData;
 
-struct nsRuleData;
 typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
 
 struct nsRuleData
 {
   PRUint32 mSIDs;
   PRPackedBool mCanStoreInRuleTree;
   PRPackedBool mIsImportantRule;
   PRUint8 mLevel; // an nsStyleSet::sheetType
   nsPresContext* mPresContext;
   nsStyleContext* mStyleContext;
   nsPostResolveFunc mPostResolveCallback;
-  nsRuleDataFont* mFontData; // Should always be stack-allocated! We don't own these structures!
+
+  // Should always be stack-allocated! We don't own these structures!
+  nsRuleDataFont* mFontData;
   nsRuleDataDisplay* mDisplayData;
   nsRuleDataMargin* mMarginData;
   nsRuleDataList* mListData;
   nsRuleDataPosition* mPositionData;
   nsRuleDataTable* mTableData;
   nsRuleDataColor* mColorData;
   nsRuleDataContent* mContentData;
   nsRuleDataText* mTextData;
   nsRuleDataUserInterface* mUserInterfaceData;
   nsRuleDataXUL* mXULData;
   nsRuleDataSVG* mSVGData;
-
   nsRuleDataColumn* mColumnData;
 
-  nsRuleData(PRUint32 aSIDs, nsPresContext* aContext, nsStyleContext* aStyleContext) 
-    :mSIDs(aSIDs), mPresContext(aContext), mStyleContext(aStyleContext), mPostResolveCallback(nsnull),
-     mFontData(nsnull), mDisplayData(nsnull), mMarginData(nsnull), mListData(nsnull), 
-     mPositionData(nsnull), mTableData(nsnull), mColorData(nsnull), mContentData(nsnull), mTextData(nsnull),
-     mUserInterfaceData(nsnull), mXULData(nsnull), mSVGData(nsnull), mColumnData(nsnull)
-  {
-    mCanStoreInRuleTree = PR_TRUE;
-  }
+  nsRuleData(PRUint32 aSIDs,
+             nsPresContext* aContext,
+             nsStyleContext* aStyleContext)
+    : mSIDs(aSIDs),
+      mCanStoreInRuleTree(PR_TRUE),
+      mPresContext(aContext),
+      mStyleContext(aStyleContext),
+      mPostResolveCallback(nsnull),
+      mFontData(nsnull),
+      mDisplayData(nsnull),
+      mMarginData(nsnull),
+      mListData(nsnull),
+      mPositionData(nsnull),
+      mTableData(nsnull),
+      mColorData(nsnull),
+      mContentData(nsnull),
+      mTextData(nsnull),
+      mUserInterfaceData(nsnull),
+      mXULData(nsnull),
+      mSVGData(nsnull),
+      mColumnData(nsnull)
+  {}
   ~nsRuleData() {}
+
+  /**
+   * Non-typesafe worker routine for the above five value retrieval
+   * functions.  Avoid using.
+   */
+  void* StorageFor(nsCSSProperty aProperty);
 };
 
 #endif
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -47,17 +47,16 @@
 #include "nsRuleProcessorData.h"
 #include "nsIStyleRule.h"
 #include "nsRuleWalker.h"
 #include "nsRuleData.h"
 #include "nsSMILKeySpline.h"
 #include "gfxColor.h"
 #include "nsCSSPropertySet.h"
 #include "nsStyleAnimation.h"
-#include "nsCSSDataBlock.h"
 #include "nsEventDispatcher.h"
 #include "nsGUIEvent.h"
 #include "mozilla/dom/Element.h"
 
 using mozilla::TimeStamp;
 using mozilla::TimeDuration;
 
 namespace dom = mozilla::dom;
@@ -237,18 +236,17 @@ AnimValuesStyleRule::MapRuleInfoInto(nsR
     return;
   }
 
   for (PRUint32 i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
     PropertyValuePair &cv = mPropertyValuePairs[i];
     if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
                              nsCSSProps::kSIDTable[cv.mProperty]))
     {
-      void *prop =
-        nsCSSExpandedDataBlock::RuleDataPropertyAt(aRuleData, cv.mProperty);
+      void *prop = aRuleData->StorageFor(cv.mProperty);
 #ifdef DEBUG
       PRBool ok =
 #endif
         nsStyleAnimation::UncomputeValue(cv.mProperty, aRuleData->mPresContext,
                                          cv.mValue, prop);
       NS_ABORT_IF_FALSE(ok, "could not store computed value");
     }
   }