System/PCL: Implement HttpWebRequest.SupportsCookieContainer, WebRequest.CreateHttp...
[mono.git] / mcs / class / System / System.Collections.Generic / SortedList.cs
index 259d0f8236f17714cf254a3f9dd41474103812c4..5ee7bfb94eebc42654b120cef9e0bae72ee06b1b 100644 (file)
@@ -169,10 +169,10 @@ namespace System.Collections.Generic
 
                object IDictionary.this [object key] {
                        get {
-                               if (!(key is TKey))
-                                       return null;
-                               else
-                                       return this [(TKey)key];
+                               TValue obj;
+                               if (key is TKey && TryGetValue ((TKey)key, out obj))
+                                       return obj;
+                               return null;
                        }
 
                        set {
@@ -305,16 +305,12 @@ namespace System.Collections.Generic
 
                void ICollection<KeyValuePair<TKey, TValue>>.Clear () 
                {
-                       defaultCapacity = INITIAL_SIZE;
-                       this.table = new KeyValuePair<TKey, TValue> [defaultCapacity];
-                       inUse = 0;
-                       modificationCount++;
+                       Clear ();
                }
 
                public void Clear () 
                {
-                       defaultCapacity = INITIAL_SIZE;
-                       this.table = new KeyValuePair<TKey, TValue> [defaultCapacity];
+                       Array.Clear (table, 0, table.Length);
                        inUse = 0;
                        modificationCount++;
                }
@@ -633,7 +629,7 @@ namespace System.Collections.Generic
                        int right = len-1;
 
                        while (left <= right) {
-                               int guess = (left + right) >> 1;
+                               int guess = left + ((right - left) >> 1);
 
                                int cmp = Compare (table[guess].Key, key);
                                if (cmp == 0) return guess;