Bug 1368369 - pt 1 - Use nsTArray instead of AutoTArray in FrameProperties, and embed the FrameProperties object directly in nsIFrame. r=mats
authorJonathan Kew <jkew@mozilla.com>
Wed, 31 May 2017 19:52:53 +0100
changeset 409766 4abbee1979c215ffbf126534d45bf1ca76c0b29b
parent 409765 3947c1473651b4736840973914f83d655e3acbe3
child 409767 0ea05f32de96073ce623e0831c0f79a65daebda0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1368369
milestone55.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 1368369 - pt 1 - Use nsTArray instead of AutoTArray in FrameProperties, and embed the FrameProperties object directly in nsIFrame. r=mats
layout/base/FrameProperties.cpp
layout/base/FrameProperties.h
layout/generic/nsFrame.cpp
layout/generic/nsIFrame.h
--- a/layout/base/FrameProperties.cpp
+++ b/layout/base/FrameProperties.cpp
@@ -23,31 +23,25 @@ FrameProperties::SetInternal(UntypedDesc
   if (index != nsTArray<PropertyValue>::NoIndex) {
     PropertyValue* pv = &mProperties.ElementAt(index);
     pv->DestroyValueFor(aFrame);
     pv->mValue = aValue;
     return;
   }
 
   mProperties.AppendElement(PropertyValue(aProperty, aValue));
-#ifdef DEBUG
-  mMaxLength = std::max<uint32_t>(mMaxLength, mProperties.Length());
-#endif
 }
 
 void
 FrameProperties::AddInternal(UntypedDescriptor aProperty, void* aValue)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aProperty, "Null property?");
 
   mProperties.AppendElement(PropertyValue(aProperty, aValue));
-#ifdef DEBUG
-  mMaxLength = std::max<uint32_t>(mMaxLength, mProperties.Length());
-#endif
 }
 
 void*
 FrameProperties::RemoveInternal(UntypedDescriptor aProperty, bool* aFoundResult)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aProperty, "Null property?");
 
--- a/layout/base/FrameProperties.h
+++ b/layout/base/FrameProperties.h
@@ -145,25 +145,21 @@ public:
   template<typename T>
   using Descriptor = const FramePropertyDescriptor<T>*;
   using UntypedDescriptor = const FramePropertyDescriptorUntyped*;
 
   template<typename T>
   using PropertyType = typename detail::FramePropertyTypeHelper<T>::Type;
 
   explicit FrameProperties()
-#ifdef DEBUG
-    : mMaxLength(0)
-#endif
   {
   }
 
   ~FrameProperties()
   {
-    MOZ_ASSERT(mMaxLength > 0, "redundant FrameProperties!");
     MOZ_ASSERT(mProperties.Length() == 0, "forgot to delete properties");
   }
 
   /**
    * Set a property value. This requires a linear search through
    * the properties of the frame. Any existing value for the property
    * is destroyed.
    */
@@ -359,20 +355,17 @@ private:
     bool Equals(UntypedDescriptor a, const PropertyValue& b) const {
       return a == b.mProperty;
     }
     bool Equals(const PropertyValue& a, UntypedDescriptor b) const {
       return a.mProperty == b;
     }
   };
 
-  AutoTArray<PropertyValue,1> mProperties;
-#ifdef DEBUG
-  uint32_t mMaxLength;
-#endif
+  nsTArray<PropertyValue> mProperties;
 };
 
 inline void*
 FrameProperties::GetInternal(UntypedDescriptor aProperty,
                              bool* aFoundResult) const
 {
   MOZ_ASSERT(aProperty, "Null property?");
 
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10549,19 +10549,17 @@ nsFrame::HasCSSTransitions()
   return collection && collection->mAnimations.Length() > 0;
 }
 
 size_t
 nsIFrame::SizeOfFramePropertiesForTree(MallocSizeOf aMallocSizeOf) const
 {
   size_t result = 0;
 
-  if (mProperties) {
-    result += mProperties->SizeOfIncludingThis(aMallocSizeOf);
-  }
+  result += mProperties.SizeOfExcludingThis(aMallocSizeOf);
 
   FrameChildListIterator iter(this);
   while (!iter.IsDone()) {
     for (const nsIFrame* f : iter.CurrentList()) {
       result += f->SizeOfFramePropertiesForTree(aMallocSizeOf);
     }
     iter.Next();
   }
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -3385,84 +3385,59 @@ public:
    * These call through to the frame's FrameProperties object, if it
    * exists, but avoid creating it if no property is ever set.
    */
   template<typename T>
   FrameProperties::PropertyType<T>
   GetProperty(FrameProperties::Descriptor<T> aProperty,
               bool* aFoundResult = nullptr) const
   {
-    if (mProperties) {
-      return mProperties->Get(aProperty, aFoundResult);
-    }
-    if (aFoundResult) {
-      *aFoundResult = false;
-    }
-    return FrameProperties::ReinterpretHelper<T>::FromPointer(nullptr);
+    return mProperties.Get(aProperty, aFoundResult);
   }
 
   template<typename T>
   bool HasProperty(FrameProperties::Descriptor<T> aProperty) const
   {
-    if (mProperties) {
-      return mProperties->Has(aProperty);
-    }
-    return false;
+    return mProperties.Has(aProperty);
   }
 
   // Add a property, or update an existing property for the given descriptor.
   template<typename T>
   void SetProperty(FrameProperties::Descriptor<T> aProperty,
                    FrameProperties::PropertyType<T> aValue)
   {
-    if (!mProperties) {
-      mProperties = mozilla::MakeUnique<FrameProperties>();
-    }
-    mProperties->Set(aProperty, aValue, this);
+    mProperties.Set(aProperty, aValue, this);
   }
 
   // Unconditionally add a property; use ONLY if the descriptor is known
   // to NOT already be present.
   template<typename T>
   void AddProperty(FrameProperties::Descriptor<T> aProperty,
                    FrameProperties::PropertyType<T> aValue)
   {
-    if (!mProperties) {
-      mProperties = mozilla::MakeUnique<FrameProperties>();
-    }
-    mProperties->Add(aProperty, aValue);
+    mProperties.Add(aProperty, aValue);
   }
 
   template<typename T>
   FrameProperties::PropertyType<T>
   RemoveProperty(FrameProperties::Descriptor<T> aProperty,
                  bool* aFoundResult = nullptr)
   {
-    if (mProperties) {
-      return mProperties->Remove(aProperty, aFoundResult);
-    }
-    if (aFoundResult) {
-      *aFoundResult = false;
-    }
-    return FrameProperties::ReinterpretHelper<T>::FromPointer(nullptr);
+    return mProperties.Remove(aProperty, aFoundResult);
   }
 
   template<typename T>
   void DeleteProperty(FrameProperties::Descriptor<T> aProperty)
   {
-    if (mProperties) {
-      mProperties->Delete(aProperty, this);
-    }
+    mProperties.Delete(aProperty, this);
   }
 
   void DeleteAllProperties()
   {
-    if (mProperties) {
-      mProperties->DeleteAll(this);
-    }
+    mProperties.DeleteAll(this);
   }
 
   // Reports size of the FrameProperties for this frame and its descendants
   size_t SizeOfFramePropertiesForTree(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   /**
    * Return true if and only if this frame obeys visibility:hidden.
    * if it does not, then nsContainerFrame will hide its view even though
@@ -3959,20 +3934,19 @@ protected:
     NS_ASSERTION(!(mState & NS_FRAME_IN_REFLOW), "frame is already in reflow");
 #endif
     mState |= NS_FRAME_IN_REFLOW;
   }
 
   nsFrameState     mState;
 
   /**
-   * List of properties attached to the frame, or null if no properties have
-   * been set.
-   */
-  mozilla::UniquePtr<FrameProperties> mProperties;
+   * List of properties attached to the frame.
+   */
+  FrameProperties  mProperties;
 
   // When there is an overflow area only slightly larger than mRect,
   // we store a set of four 1-byte deltas from the edges of mRect
   // rather than allocating a whole separate rectangle property.
   // Note that these are unsigned values, all measured "outwards"
   // from the edges of mRect, so /mLeft/ and /mTop/ are reversed from
   // our normal coordinate system.
   // If mOverflow.mType == NS_FRAME_OVERFLOW_LARGE, then the