Author: [email protected]
Date: Wed Mar  4 02:34:36 2009
New Revision: 1415

Modified:
    branches/bleeding_edge/src/list-inl.h
    branches/bleeding_edge/src/list.h

Log:
Add an insert function to our list utility class.
Review URL: http://codereview.chromium.org/40105

Modified: branches/bleeding_edge/src/list-inl.h
==============================================================================
--- branches/bleeding_edge/src/list-inl.h       (original)
+++ branches/bleeding_edge/src/list-inl.h       Wed Mar  4 02:34:36 2009
@@ -59,6 +59,18 @@


  template<typename T, class P>
+T& List<T, P>::Insert(int i, const T& element) {
+  int free_index = length_ - 1;
+  Add(last());  // Add grows the list if necessary.
+  while (free_index > i) {
+    data_[free_index] = data_[free_index - 1];
+    free_index--;
+  }
+  data_[free_index] = element;
+}
+
+
+template<typename T, class P>
  T List<T, P>::Remove(int i) {
    T element = at(i);
    length_--;

Modified: branches/bleeding_edge/src/list.h
==============================================================================
--- branches/bleeding_edge/src/list.h   (original)
+++ branches/bleeding_edge/src/list.h   Wed Mar  4 02:34:36 2009
@@ -79,9 +79,16 @@
    // until the next change is made to this list.
    Vector<T> AddBlock(const T& value, int count);

+  // Inserts a copy of the given element at index i in the list.  All
+  // elements formerly at or above i are moved up and the length of
+  // the list increases by one.  This function's complexity is linear
+  // in the size of the list.
+  T& Insert(int i, const T& element);
+
    // Removes the i'th element without deleting it even if T is a
    // pointer type; moves all elements above i "down". Returns the
-  // removed element.
+  // removed element.  This function's complexity is linear in the
+  // size of the list.
    T Remove(int i);

    // Removes the last element without deleting it even if T is a

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to