Bug 1208951 - Part 2: Use a comparator object instead of operator< on KeyframeValueEntry. r=birtles
authorCameron McCormack <cam@mcc.id.au>
Thu, 22 Oct 2015 19:22:37 +1100
changeset 304127 570802c94583bc07f56c8aae24d1a3f872fb47d1
parent 304126 0ac4e2e6cb78db629e6d33d89fba5cc01dda945f
child 304128 b703a449fd3a3a503dd1eddf51474f9931f2dcba
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1208951
milestone44.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 1208951 - Part 2: Use a comparator object instead of operator< on KeyframeValueEntry. r=birtles
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -540,43 +540,44 @@ protected:
  * to gather the data for each individual segment described by
  * mProperties so that they can be manipulated into a sequence<Keyframe>.
  */
 struct KeyframeStringValueEntry : KeyframeValueEntry
 {
   nsString mValue;
   const ComputedTimingFunction* mTimingFunction;
 
-  bool operator==(const KeyframeStringValueEntry& aRhs) const
+  struct OffsetEasingPropertyComparator
   {
-    NS_ASSERTION(mOffset != aRhs.mOffset || mProperty != aRhs.mProperty,
-                 "shouldn't have duplicate (offset, property) pairs");
-    return false;
-  }
-
-  bool operator<(const KeyframeStringValueEntry& aRhs) const
-  {
-    NS_ASSERTION(mOffset != aRhs.mOffset || mProperty != aRhs.mProperty,
-                 "shouldn't have duplicate (offset, property) pairs");
+    bool Equals(const KeyframeStringValueEntry& aLhs,
+                const KeyframeStringValueEntry& aRhs) const
+    {
+      return aLhs.mOffset == aRhs.mOffset &&
+             aLhs.mProperty == aRhs.mProperty &&
+             *aLhs.mTimingFunction == *aRhs.mTimingFunction;
+    }
+    bool LessThan(const KeyframeStringValueEntry& aLhs,
+                  const KeyframeStringValueEntry& aRhs) const
+    {
+      // First, sort by offset.
+      if (aLhs.mOffset != aRhs.mOffset) {
+        return aLhs.mOffset < aRhs.mOffset;
+      }
 
-    // First, sort by offset.
-    if (mOffset != aRhs.mOffset) {
-      return mOffset < aRhs.mOffset;
-    }
+      // Second, by timing function.
+      int32_t order = aLhs.mTimingFunction->Compare(*aRhs.mTimingFunction);
+      if (order != 0) {
+        return order < 0;
+      }
 
-    // Second, by timing function.
-    int32_t order = mTimingFunction->Compare(*aRhs.mTimingFunction);
-    if (order != 0) {
-      return order < 0;
+      // Last, by property IDL name.
+      return nsCSSProps::PropertyIDLNameSortPosition(aLhs.mProperty) <
+             nsCSSProps::PropertyIDLNameSortPosition(aRhs.mProperty);
     }
-
-    // Last, by property IDL name.
-    return nsCSSProps::PropertyIDLNameSortPosition(mProperty) <
-           nsCSSProps::PropertyIDLNameSortPosition(aRhs.mProperty);
-  }
+  };
 };
 
 void
 KeyframeEffectReadOnly::GetFrames(JSContext*& aCx,
                                   nsTArray<JSObject*>& aResult,
                                   ErrorResult& aRv)
 {
   // Collect tuples of the form (offset, property, value, easing) from
@@ -606,17 +607,17 @@ KeyframeEffectReadOnly::GetFrames(JSCont
     // We don't have the an appropriate animation-timing-function value to use,
     // either from the element or from the 100% keyframe, so we just set it to
     // the animation-timing-value value used on the previous segment.
     entry->mTimingFunction = &segment.mTimingFunction;
     StyleAnimationValue::UncomputeValue(property.mProperty,
                                         segment.mToValue,
                                         entry->mValue);
   }
-  entries.Sort();
+  entries.Sort(KeyframeStringValueEntry::OffsetEasingPropertyComparator());
 
   for (size_t i = 0, n = entries.Length(); i < n; ) {
     // Create a JS object with the explicit ComputedKeyframe dictionary members.
     ComputedKeyframe keyframeDict;
     keyframeDict.mOffset.SetValue(entries[i].mOffset);
     keyframeDict.mComputedOffset.Construct(entries[i].mOffset);
     keyframeDict.mEasing.Truncate();
     entries[i].mTimingFunction->AppendToString(keyframeDict.mEasing);