Bug 1245748 - Add PropertyPriorityIterator; r=heycam
authorBrian Birtles <birtles@gmail.com>
Tue, 22 Mar 2016 16:33:16 +0900
changeset 290211 2d6642da5c506cbe5f210af3103dbebb8299be05
parent 290210 a292ea900280e9f1fd743c5bcddfe06435fea5a8
child 290212 0ea9096a60d242edf82ecf3d6ebfcd933988ec65
push id30114
push usercbook@mozilla.com
push dateThu, 24 Mar 2016 15:15:54 +0000
treeherdermozilla-central@24c5fbde4488 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1245748
milestone48.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 1245748 - Add PropertyPriorityIterator; r=heycam MozReview-Commit-ID: JjBWcyEG3f6
dom/animation/KeyframeUtils.cpp
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -137,16 +137,90 @@ public:
   }
   bool LessThan(const T& aLhs, const T& aRhs) const
   {
     return PropertyPriorityComparator::LessThan(aLhs.mProperty, aRhs.mProperty);
   }
 };
 
 /**
+ * Iterator to walk through a PropertyValuePair array using the ordering
+ * provided by PropertyPriorityComparator.
+ */
+class PropertyPriorityIterator
+{
+public:
+  explicit PropertyPriorityIterator(
+    const nsTArray<PropertyValuePair>& aProperties)
+    : mProperties(aProperties)
+  {
+    mSortedPropertyIndices.SetCapacity(mProperties.Length());
+    for (size_t i = 0, len = mProperties.Length(); i < len; ++i) {
+      PropertyAndIndex propertyIndex = { mProperties[i].mProperty, i };
+      mSortedPropertyIndices.AppendElement(propertyIndex);
+    }
+    mSortedPropertyIndices.Sort(PropertyAndIndex::Comparator());
+  }
+
+  class Iter
+  {
+  public:
+    explicit Iter(const PropertyPriorityIterator& aParent)
+      : mParent(aParent)
+      , mIndex(0) { }
+
+    static Iter EndIter(const PropertyPriorityIterator &aParent)
+    {
+      Iter iter(aParent);
+      iter.mIndex = aParent.mSortedPropertyIndices.Length();
+      return iter;
+    }
+
+    bool operator!=(const Iter& aOther) const
+    {
+      return mIndex != aOther.mIndex;
+    }
+
+    Iter& operator++()
+    {
+      MOZ_ASSERT(mIndex + 1 <= mParent.mSortedPropertyIndices.Length(),
+                 "Should not seek past end iterator");
+      mIndex++;
+      return *this;
+    }
+
+    const PropertyValuePair& operator*()
+    {
+      MOZ_ASSERT(mIndex < mParent.mSortedPropertyIndices.Length(),
+                 "Should not try to dereference an end iterator");
+      return mParent.mProperties[mParent.mSortedPropertyIndices[mIndex].mIndex];
+    }
+
+  private:
+    const PropertyPriorityIterator& mParent;
+    size_t mIndex;
+  };
+
+  Iter begin() { return Iter(*this); }
+  Iter end()   { return Iter::EndIter(*this); }
+
+private:
+  struct PropertyAndIndex
+  {
+    nsCSSProperty mProperty;
+    size_t mIndex; // Index of mProperty within mProperties
+
+    typedef TPropertyPriorityComparator<PropertyAndIndex> Comparator;
+  };
+
+  const nsTArray<PropertyValuePair>& mProperties;
+  nsTArray<PropertyAndIndex> mSortedPropertyIndices;
+};
+
+/**
  * A property-values pair obtained from the open-ended properties
  * discovered on a regular keyframe or property-indexed keyframe object.
  *
  * Single values (as required by a regular keyframe, and as also supported
  * on property-indexed keyframes) are stored as the only element in
  * mValues.
  */
 struct PropertyValuesPair