Bug 1368369 - pt 2 - Move internal FrameProperties methods to the header as inlines, for better optimization opportunities. r=mats
authorJonathan Kew <jkew@mozilla.com>
Wed, 31 May 2017 19:52:56 +0100
changeset 409767 0ea05f32de96073ce623e0831c0f79a65daebda0
parent 409766 4abbee1979c215ffbf126534d45bf1ca76c0b29b
child 409768 96875dd613f8bb6691f5c0bbcfd28a0501145f79
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 2 - Move internal FrameProperties methods to the header as inlines, for better optimization opportunities. r=mats
layout/base/FrameProperties.cpp
layout/base/FrameProperties.h
layout/base/moz.build
deleted file mode 100644
--- a/layout/base/FrameProperties.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "FrameProperties.h"
-
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/ServoStyleSet.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-
-void
-FrameProperties::SetInternal(UntypedDescriptor aProperty, void* aValue,
-                             const nsIFrame* aFrame)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aProperty, "Null property?");
-
-  nsTArray<PropertyValue>::index_type index =
-    mProperties.IndexOf(aProperty, 0, PropertyComparator());
-  if (index != nsTArray<PropertyValue>::NoIndex) {
-    PropertyValue* pv = &mProperties.ElementAt(index);
-    pv->DestroyValueFor(aFrame);
-    pv->mValue = aValue;
-    return;
-  }
-
-  mProperties.AppendElement(PropertyValue(aProperty, aValue));
-}
-
-void
-FrameProperties::AddInternal(UntypedDescriptor aProperty, void* aValue)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aProperty, "Null property?");
-
-  mProperties.AppendElement(PropertyValue(aProperty, aValue));
-}
-
-void*
-FrameProperties::RemoveInternal(UntypedDescriptor aProperty, bool* aFoundResult)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aProperty, "Null property?");
-
-  nsTArray<PropertyValue>::index_type index =
-    mProperties.IndexOf(aProperty, 0, PropertyComparator());
-  if (index == nsTArray<PropertyValue>::NoIndex) {
-    if (aFoundResult) {
-      *aFoundResult = false;
-    }
-    return nullptr;
-  }
-
-  if (aFoundResult) {
-    *aFoundResult = true;
-  }
-
-  void* result = mProperties.ElementAt(index).mValue;
-  mProperties.RemoveElementAt(index);
-
-  return result;
-}
-
-void
-FrameProperties::DeleteInternal(UntypedDescriptor aProperty,
-                                const nsIFrame* aFrame)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aProperty, "Null property?");
-
-  bool found;
-  void* v = RemoveInternal(aProperty, &found);
-  if (found) {
-    PropertyValue pv(aProperty, v);
-    pv.DestroyValueFor(aFrame);
-  }
-}
-
-void
-FrameProperties::DeleteAll(const nsIFrame* aFrame)
-{
-  for (uint32_t i = 0; i < mProperties.Length(); ++i) {
-    mProperties.ElementAt(i).DestroyValueFor(aFrame);
-  }
-
-  mProperties.Clear();
-}
-
-size_t
-FrameProperties::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
-{
-  // We currently report only the shallow size of the mProperties array.
-  // As for the PropertyValue entries: we don't need to measure the mProperty
-  // field of because it always points to static memory, and we can't measure
-  // mValue because the type is opaque.
-  // XXX Can we do better, e.g. with a method on the descriptor?
-  return mProperties.ShallowSizeOfExcludingThis(aMallocSizeOf);
-}
-
-} // namespace mozilla
--- a/layout/base/FrameProperties.h
+++ b/layout/base/FrameProperties.h
@@ -1,20 +1,22 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef FRAMEPROPERTIES_H_
 #define FRAMEPROPERTIES_H_
 
+#include "mozilla/DebugOnly.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/Unused.h"
 #include "nsTArray.h"
+#include "nsThreadUtils.h"
 
 class nsIFrame;
 
 namespace mozilla {
 
 struct FramePropertyDescriptorUntyped
 {
   /**
@@ -256,42 +258,57 @@ public:
   void Delete(Descriptor<T> aProperty, const nsIFrame* aFrame)
   {
     DeleteInternal(aProperty, aFrame);
   }
 
   /**
    * Remove and destroy all property values for the frame.
    */
-  void DeleteAll(const nsIFrame* aFrame);
+  void DeleteAll(const nsIFrame* aFrame) {
+    mozilla::DebugOnly<size_t> len = mProperties.Length();
+    for (auto& prop : mProperties) {
+      prop.DestroyValueFor(aFrame);
+      MOZ_ASSERT(mProperties.Length() == len);
+    }
+    mProperties.Clear();
+  }
 
-  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
-    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
+    // We currently report only the shallow size of the mProperties array.
+    // As for the PropertyValue entries: we don't need to measure the mProperty
+    // field of because it always points to static memory, and we can't measure
+    // mValue because the type is opaque.
+    // XXX Can we do better, e.g. with a method on the descriptor?
+    return mProperties.ShallowSizeOfExcludingThis(aMallocSizeOf);
   }
 
 private:
   friend class ::nsIFrame;
 
   // Prevent copying of FrameProperties; we should always return/pass around
   // references to it, not copies!
   FrameProperties(const FrameProperties&) = delete;
   FrameProperties& operator=(const FrameProperties&) = delete;
 
-  void SetInternal(UntypedDescriptor aProperty, void* aValue,
-                   const nsIFrame* aFrame);
+  inline void
+  SetInternal(UntypedDescriptor aProperty, void* aValue,
+              const nsIFrame* aFrame);
 
-  void AddInternal(UntypedDescriptor aProperty, void* aValue);
+  inline void
+  AddInternal(UntypedDescriptor aProperty, void* aValue);
 
   inline void*
   GetInternal(UntypedDescriptor aProperty, bool* aFoundResult) const;
 
-  void* RemoveInternal(UntypedDescriptor aProperty, bool* aFoundResult);
+  inline void*
+  RemoveInternal(UntypedDescriptor aProperty, bool* aFoundResult);
 
-  void DeleteInternal(UntypedDescriptor aProperty, const nsIFrame* aFrame);
+  inline void
+  DeleteInternal(UntypedDescriptor aProperty, const nsIFrame* aFrame);
 
   template<typename T>
   struct ReinterpretHelper
   {
     static_assert(sizeof(PropertyType<T>) <= sizeof(void*),
                   "size of the value must never be larger than a pointer");
 
     static void* ToPointer(PropertyType<T> aValue)
@@ -358,32 +375,97 @@ private:
     bool Equals(const PropertyValue& a, UntypedDescriptor b) const {
       return a.mProperty == b;
     }
   };
 
   nsTArray<PropertyValue> mProperties;
 };
 
+
 inline void*
 FrameProperties::GetInternal(UntypedDescriptor aProperty,
                              bool* aFoundResult) const
 {
   MOZ_ASSERT(aProperty, "Null property?");
 
-  nsTArray<PropertyValue>::index_type index =
-    mProperties.IndexOf(aProperty, 0, PropertyComparator());
+  auto index = mProperties.IndexOf(aProperty, 0, PropertyComparator());
   if (index == nsTArray<PropertyValue>::NoIndex) {
     if (aFoundResult) {
       *aFoundResult = false;
     }
     return nullptr;
   }
 
   if (aFoundResult) {
     *aFoundResult = true;
   }
   return mProperties.ElementAt(index).mValue;
 }
 
+inline void
+FrameProperties::SetInternal(UntypedDescriptor aProperty, void* aValue,
+                             const nsIFrame* aFrame)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProperty, "Null property?");
+
+  auto index = mProperties.IndexOf(aProperty, 0, PropertyComparator());
+  if (index != nsTArray<PropertyValue>::NoIndex) {
+    PropertyValue* pv = &mProperties.ElementAt(index);
+    pv->DestroyValueFor(aFrame);
+    pv->mValue = aValue;
+    return;
+  }
+
+  mProperties.AppendElement(PropertyValue(aProperty, aValue));
+}
+
+inline void
+FrameProperties::AddInternal(UntypedDescriptor aProperty, void* aValue)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProperty, "Null property?");
+
+  mProperties.AppendElement(PropertyValue(aProperty, aValue));
+}
+
+inline void*
+FrameProperties::RemoveInternal(UntypedDescriptor aProperty, bool* aFoundResult)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProperty, "Null property?");
+
+  auto index = mProperties.IndexOf(aProperty, 0, PropertyComparator());
+  if (index == nsTArray<PropertyValue>::NoIndex) {
+    if (aFoundResult) {
+      *aFoundResult = false;
+    }
+    return nullptr;
+  }
+
+  if (aFoundResult) {
+    *aFoundResult = true;
+  }
+
+  void* result = mProperties.ElementAt(index).mValue;
+  mProperties.RemoveElementAt(index);
+
+  return result;
+}
+
+inline void
+FrameProperties::DeleteInternal(UntypedDescriptor aProperty,
+                                const nsIFrame* aFrame)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProperty, "Null property?");
+
+  auto index = mProperties.IndexOf(aProperty, 0, PropertyComparator());
+  if (index != nsTArray<PropertyValue>::NoIndex) {
+    mProperties.ElementAt(index).DestroyValueFor(aFrame);
+    mProperties.RemoveElementAt(index);
+  }
+}
+
 } // namespace mozilla
 
 #endif /* FRAMEPROPERTIES_H_ */
--- a/layout/base/moz.build
+++ b/layout/base/moz.build
@@ -82,17 +82,16 @@ EXPORTS.mozilla += [
     'ShapeUtils.h',
     'StaticPresData.h',
 ]
 
 UNIFIED_SOURCES += [
     'AccessibleCaret.cpp',
     'AccessibleCaretEventHub.cpp',
     'AccessibleCaretManager.cpp',
-    'FrameProperties.cpp',
     'GeckoRestyleManager.cpp',
     'GeometryUtils.cpp',
     'LayoutLogging.cpp',
     'MobileViewportManager.cpp',
     'nsBidiPresUtils.cpp',
     'nsCaret.cpp',
     'nsCounterManager.cpp',
     'nsCSSColorUtils.cpp',