Bug 944291 - Part 1: Add SplayTree::find. r=waldo, a=lsblakk
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 13 Dec 2013 16:12:07 +1300
changeset 175607 1c16411289e4bc4202c5786fc463ed7a978f8afc
parent 175606 bfc367d67c4a0f48297460d7634e2cc974e9b6fa
child 175608 89680c49db3b77ff338a1fccd93b8f1e6a067394
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo, lsblakk
bugs944291
milestone28.0a2
Bug 944291 - Part 1: Add SplayTree::find. r=waldo, a=lsblakk
layout/base/RestyleTracker.h
mfbt/SplayTree.h
--- a/layout/base/RestyleTracker.h
+++ b/layout/base/RestyleTracker.h
@@ -47,31 +47,31 @@ public:
    * areas instead of UpdateOverflow().
    *
    * If the overflow area changes, then UpdateOverflow will also
    * be called on the parent.
    */
   void AddFrame(nsIFrame* aFrame) {
     uint32_t depth = aFrame->GetDepthInFrameTree();
     if (mEntryList.empty() ||
-        !mEntryList.contains(Entry(aFrame, depth, true))) {
+        !mEntryList.find(Entry(aFrame, depth, true))) {
       mEntryList.insert(new Entry(aFrame, depth, true));
     }
   }
 
   /**
    * Remove a frame.
    */
   void RemoveFrame(nsIFrame* aFrame) {
     if (mEntryList.empty()) {
       return;
     }
 
     uint32_t depth = aFrame->GetDepthInFrameTree();
-    if (mEntryList.contains(Entry(aFrame, depth, false))) {
+    if (mEntryList.find(Entry(aFrame, depth, false))) {
       delete mEntryList.remove(Entry(aFrame, depth, false));
     }
   }
 
   /**
    * Set the subtree root to limit overflow updates. This must be set if and
    * only if currently reflowing aSubtreeRoot, to ensure overflow changes will
    * still propagate correctly.
@@ -109,17 +109,17 @@ public:
       // If the overflow changed, then we want to also update the parent's
       // overflow. We always update the parent for initial frames.
       if (!updateParent) {
         updateParent = frame->UpdateOverflow() || entry->mInitial;
       }
       if (updateParent) {
         nsIFrame *parent = frame->GetParent();
         if (parent && parent != mSubtreeRoot) {
-          if (!mEntryList.contains(Entry(parent, entry->mDepth - 1, false))) {
+          if (!mEntryList.find(Entry(parent, entry->mDepth - 1, false))) {
             mEntryList.insert(new Entry(parent, entry->mDepth - 1, false));
           }
         }
       }
       delete entry;
     }
   }
   
--- a/mfbt/SplayTree.h
+++ b/mfbt/SplayTree.h
@@ -58,30 +58,30 @@ class SplayTree
     SplayTree()
       : root(nullptr), freeList(nullptr)
     {}
 
     bool empty() const {
       return !root;
     }
 
-    bool contains(const T& v)
+    T* find(const T& v)
     {
       if (empty())
-        return false;
+        return nullptr;
 
       T* last = lookup(v);
       splay(last);
       checkCoherency(root, nullptr);
-      return Comparator::compare(v, *last) == 0;
+      return Comparator::compare(v, *last) == 0 ? last : nullptr;
     }
 
     bool insert(T* v)
     {
-      MOZ_ASSERT(!contains(*v), "Duplicate elements are not allowed.");
+      MOZ_ASSERT(!find(*v), "Duplicate elements are not allowed.");
 
       if (!root) {
         root = v;
         return true;
       }
       T* last = lookup(*v);
       int cmp = Comparator::compare(*v, *last);