2009-06-25 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / System.Collections.Generic / List.cs
index fc9f02261e990aaba95fddba6fa02714dbee2189..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)
@@ -401,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)
@@ -515,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);