2005-04-25 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Collections.Generic / Queue.cs
index 924582aa671558c2470871f4c7c4862a9c52ddee..5aecbf433cb7bb365310592f939a82484e8898a3 100644 (file)
@@ -70,7 +70,10 @@ namespace System.Collections.Generic
                
                public void Clear ()
                {
-                       Array.Clear (data, 0, data.Length);
+                       if (data != null)
+                               Array.Clear (data, 0, data.Length);
+                       
+                       head = tail = size = 0;
                }
                
                public bool Contains (T item)
@@ -93,12 +96,15 @@ namespace System.Collections.Generic
                        if (array == null)
                                throw new ArgumentNullException ();
                        
-                       if ((uint) idx < (uint) array.Length)
+                       if ((uint) idx > (uint) array.Length)
                                throw new ArgumentOutOfRangeException ();
                        
                        if (array.Length - idx < size)
                                throw new ArgumentOutOfRangeException ();
                        
+                       if (size == 0)
+                               return;
+                       
                        int contents_length = data.Length;
                        int length_from_head = contents_length - head;
                        
@@ -200,7 +206,8 @@ namespace System.Collections.Generic
                                CopyTo (new_data, 0);
                        
                        data = new_data;
-                       tail = head = 0;
+                       tail = size;
+                       head = 0;
                        version ++;
                }