Bug 1299741 part 7 - Make unit of StyleAnimationValue and nsCSSValue uint16_t and add an extra data field. r?dbaron draft
authorXidorn Quan <xidorn+moz@upsuper.org>
Thu, 01 Sep 2016 11:49:34 +1000
changeset 408688 cc2032b2f389e08744c47e75a45e5a5889908dc8
parent 408687 583328f5fc2a2ce0e564c73bca17b567e1097b4e
child 408689 db21964b9e05bf45b8485350ac10110e76adcdac
push id28271
push userxquan@mozilla.com
push dateThu, 01 Sep 2016 14:23:32 +0000
reviewersdbaron
bugs1299741
milestone51.0a1
Bug 1299741 part 7 - Make unit of StyleAnimationValue and nsCSSValue uint16_t and add an extra data field. r?dbaron So that we can make use of the padding space in StyleAnimationValue and nsCSSValue to store extra data up to 16 bits. This would be useful to avoid additional allocation for storing StyleComplexColor introduced in some later patch. MozReview-Commit-ID: 7OL9Fwuq2
layout/style/StyleAnimationValue.cpp
layout/style/StyleAnimationValue.h
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -4326,16 +4326,17 @@ StyleAnimationValue::operator=(const Sty
 {
   if (this == &aOther) {
     return *this;
   }
 
   FreeValue();
 
   mUnit = aOther.mUnit;
+  mExtra = aOther.mExtra;
   switch (mUnit) {
     case eUnit_Null:
     case eUnit_Normal:
     case eUnit_Auto:
     case eUnit_None:
     case eUnit_CurrentColor:
       break;
     case eUnit_Enumerated:
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -264,17 +264,17 @@ public:
 
   static already_AddRefed<nsCSSValue::Array>
     AppendTransformFunction(nsCSSKeyword aTransformFunction,
                             nsCSSValueList**& aListTail);
 
   /**
    * The types and values for the values that we extract and animate.
    */
-  enum Unit {
+  enum Unit : uint16_t {
     eUnit_Null, // not initialized
     eUnit_Normal,
     eUnit_Auto,
     eUnit_None,
     eUnit_Enumerated,
     eUnit_Visibility, // special case for transitions (which converts
                       // Enumerated to Visibility as needed)
     eUnit_Integer,
@@ -299,16 +299,17 @@ public:
     eUnit_Transform, // nsCSSValueList* (never null)
     eUnit_BackgroundPositionCoord, // nsCSSValueList* (never null)
     eUnit_CSSValuePairList, // nsCSSValuePairList* (never null)
     eUnit_UnparsedString // nsStringBuffer* (never null)
   };
 
 private:
   Unit mUnit;
+  uint16_t mExtra;
   union {
     int32_t mInt;
     nscoord mCoord;
     float mFloat;
     nscolor mColor;
     nsCSSValue* mCSSValue;
     nsCSSValuePair* mCSSValuePair;
     nsCSSValueTriplet* mCSSValueTriplet;
@@ -416,16 +417,17 @@ public:
     NS_ASSERTION(aUnit == eUnit_Null || aUnit == eUnit_Normal ||
                  aUnit == eUnit_Auto || aUnit == eUnit_None,
                  "must be valueless unit");
   }
   StyleAnimationValue(const StyleAnimationValue& aOther)
     : mUnit(eUnit_Null) { *this = aOther; }
   StyleAnimationValue(StyleAnimationValue&& aOther)
     : mUnit(aOther.mUnit)
+    , mExtra(aOther.mExtra)
     , mValue(aOther.mValue)
   {
     aOther.mUnit = eUnit_Null;
   }
   enum IntegerConstructorType { IntegerConstructor };
   StyleAnimationValue(int32_t aInt, Unit aUnit, IntegerConstructorType);
   enum CoordConstructorType { CoordConstructor };
   StyleAnimationValue(nscoord aLength, CoordConstructorType);
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -134,16 +134,17 @@ nsCSSValue::nsCSSValue(css::FontFamilyLi
   : mUnit(eCSSUnit_FontFamilyList)
 {
   mValue.mFontFamilyList = aValue;
   mValue.mFontFamilyList->AddRef();
 }
 
 nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
   : mUnit(aCopy.mUnit)
+  , mExtra(aCopy.mExtra)
 {
   if (mUnit <= eCSSUnit_DummyInherit) {
     // nothing to do, but put this important case first
   }
   else if (eCSSUnit_Percent <= mUnit) {
     mValue.mFloat = aCopy.mValue.mFloat;
     MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
   }
@@ -235,16 +236,17 @@ nsCSSValue& nsCSSValue::operator=(const 
 
 nsCSSValue&
 nsCSSValue::operator=(nsCSSValue&& aOther)
 {
   MOZ_ASSERT(this != &aOther, "Self assigment with rvalue reference");
 
   Reset();
   mUnit = aOther.mUnit;
+  mExtra = aOther.mExtra;
   mValue = aOther.mValue;
   aOther.mUnit = eCSSUnit_Null;
 
   return *this;
 }
 
 bool nsCSSValue::operator==(const nsCSSValue& aOther) const
 {
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -292,17 +292,17 @@ private:
     ~FontFamilyListRefCnt() {
         MOZ_COUNT_DTOR(FontFamilyListRefCnt);
     }
 };
 
 } // namespace css
 } // namespace mozilla
 
-enum nsCSSUnit {
+enum nsCSSUnit : uint16_t {
   eCSSUnit_Null         = 0,      // (n/a) null unit, value is not specified
   eCSSUnit_Auto         = 1,      // (n/a) value is algorithmic
   eCSSUnit_Inherit      = 2,      // (n/a) value is inherited
   eCSSUnit_Initial      = 3,      // (n/a) value is default UA value
   eCSSUnit_Unset        = 4,      // (n/a) value equivalent to 'initial' if on a reset property, 'inherit' otherwise
   eCSSUnit_None         = 5,      // (n/a) value is none
   eCSSUnit_Normal       = 6,      // (n/a) value is normal (algorithmic, different than auto)
   eCSSUnit_System_Font  = 7,      // (n/a) value is -moz-use-system-font
@@ -468,16 +468,17 @@ public:
   explicit nsCSSValue(mozilla::css::ImageValue* aValue);
   explicit nsCSSValue(nsCSSValueGradient* aValue);
   explicit nsCSSValue(nsCSSValueTokenStream* aValue);
   explicit nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue);
   explicit nsCSSValue(mozilla::css::FontFamilyListRefCnt* aValue);
   nsCSSValue(const nsCSSValue& aCopy);
   nsCSSValue(nsCSSValue&& aOther)
     : mUnit(aOther.mUnit)
+    , mExtra(aOther.mExtra)
     , mValue(aOther.mValue)
   {
     aOther.mUnit = eCSSUnit_Null;
   }
   ~nsCSSValue() { Reset(); }
 
   nsCSSValue&  operator=(const nsCSSValue& aCopy);
   nsCSSValue&  operator=(nsCSSValue&& aCopy);
@@ -833,16 +834,17 @@ private:
            Serialization aValueSerialization) const;
   void AppendBasicShapePositionToString(
            nsAString& aResult,
            Serialization aValueSerialization) const;
   void AppendInsetToString(nsCSSPropertyID aProperty, nsAString& aResult,
                            Serialization aValueSerialization) const;
 protected:
   nsCSSUnit mUnit;
+  uint16_t mExtra;
   union {
     int32_t    mInt;
     float      mFloat;
     // Note: the capacity of the buffer may exceed the length of the string.
     // If we're of a string type, mString is not null.
     nsStringBuffer* MOZ_OWNING_REF mString;
     nscolor    mColor;
     Array* MOZ_OWNING_REF mArray;