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 89528 7734e28e98f2b7470d5bc7ba2fdf93189f7b25bb
parent 89527 599a30dc3825f2738df4747542f052373e64b01e
child 89529 e7d417980de6ebfe55f17ca6a1998dfecc462971
push idunknown
push userunknown
push dateunknown
reviewerswaldo
bugs732820
milestone14.0a1
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