Bug 732820 - Part 1: Add clear() to LinkedList. r=waldo
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 09 Mar 2012 17:21:01 -0500
changeset 88664 45d2f5e2fe317cff073fdc206cfa5b154501c785
parent 88663 bd50a33d8c699a8e4f422bd407f9a89de2730358
child 88665 f7890083256286e88623561df39ac3903a5a48ac
push idunknown
push userunknown
push dateunknown
reviewerswaldo
bugs732820
milestone13.0a1
Bug 732820 - Part 1: Add clear() to LinkedList. r=waldo
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