2009-06-25 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / System.Collections.Generic / List.cs
index 1d0d8ecb6112f9d858313f3b1cecb49c90d7d95d..bec03c3998c2abe3c587a85474be4d6d2c7a341f 100644 (file)
@@ -112,10 +112,14 @@ namespace System.Collections.Generic {
                void AddCollection (ICollection <T> collection)
                {
                        int collectionCount = collection.Count;
+                       if (collectionCount == 0)
+                               return;
+
                        GrowIfNeeded (collectionCount);                  
                        collection.CopyTo (_items, _size);
                        _size += collectionCount;
                }
+
                void AddEnumerable (IEnumerable <T> enumerable)
                {
                        foreach (T t in enumerable)
@@ -166,7 +170,7 @@ namespace System.Collections.Generic {
                
                public bool Contains (T item)
                {
-                       return Array.IndexOf<T>(_items, item) != -1;
+                       return Array.IndexOf<T>(_items, item, 0, _size) != -1;
                }
                
                public List <TOutput> ConvertAll <TOutput> (Converter <T, TOutput> converter)
@@ -209,7 +213,8 @@ namespace System.Collections.Generic {
                        int i = GetIndex(0, _size, match);
                        return (i != -1) ? _items [i] : default (T);
                }
-               void CheckMatch (Predicate <T> match)
+               
+               static void CheckMatch (Predicate <T> match)
                {
                        if (match == null)
                                throw new ArgumentNullException ("match");
@@ -217,7 +222,7 @@ namespace System.Collections.Generic {
                
                public List <T> FindAll (Predicate <T> match)
                {
-                       this.CheckMatch (match);
+                       CheckMatch (match);
                        if (this._size <= 0x10000) // <= 8 * 1024 * 8 (8k in stack)
                                return this.FindAllStackBits (match);
                        else 
@@ -400,6 +405,9 @@ namespace System.Collections.Generic {
                                Array.Copy (_items, start, _items, start + delta, _size - start);
                        
                        _size += delta;
+
+                       if (delta < 0)
+                               Array.Clear (_items, _size, -delta);
                }
 
                void CheckIndex (int index)
@@ -514,6 +522,8 @@ namespace System.Collections.Generic {
                                if (!match(_items[j]))
                                        _items[i++] = _items[j];
                        }
+                       if (j - i > 0)
+                               Array.Clear (_items, i, j - i);
 
                        _size = i;
                        return (j - i);
@@ -524,6 +534,7 @@ namespace System.Collections.Generic {
                        if (index < 0 || (uint)index >= (uint)_size)
                                throw new ArgumentOutOfRangeException("index");
                        Shift (index, -1);
+                       Array.Clear (_items, _size, 1);
                        _version++;
                }