Bug 732820 - Part 1: Add clear() to LinkedList. r=waldo
authorJustin Lebar <justin.lebar@gmail.com>
Thu, 15 Mar 2012 16:30:41 -0400
changeset 89479 7734e28e98f2b7470d5bc7ba2fdf93189f7b25bb
parent 89478 599a30dc3825f2738df4747542f052373e64b01e
child 89480 e7d417980de6ebfe55f17ca6a1998dfecc462971
push id7184
push userjlebar@mozilla.com
push dateThu, 15 Mar 2012 20:34:27 +0000
treeherdermozilla-inbound@803853bf2a55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs732820
milestone14.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 732820 - Part 1: Add clear() to LinkedList. r=waldo
js/src/jsfun.cpp
mfbt/LinkedList.h
--- a/mfbt/LinkedList.h
+++ b/mfbt/LinkedList.h
@@ -351,16 +351,28 @@ public:
      * Return true if the list is empty, or false otherwise.
      */
     bool isEmpty()
     {
         return !sentinel.isInList();
     }
 
     /*
+     * Remove all the elements from the list.
+     *
+     * This runs in time linear to the list's length, because we have to mark
+     * each element as not in the list.
+     */
+    void clear()
+    {
+        while (popFirst())
+            continue;
+    }
+
+    /*
      * In a debug build, make sure that the list is sane (no cycles, consistent
      * next/prev pointers, only one sentinel).  Has no effect in release builds.
      */
     void debugAssertIsSane()
     {
 #ifdef DEBUG
         /*
          * Check for cycles in the forward singly-linked list using the