Bladeren bron

2006-08-16 Miguel de Icaza <[email protected]>

	* Hashtable.cs (PutImpl): Do not access the table twice, only
	once. 
	
	(TestPrime): optimize, take the sqrt out of the loop.

svn path=/trunk/mcs/; revision=64217
Miguel de Icaza 19 jaren geleden
bovenliggende
commit
2da7bc41d2
2 gewijzigde bestanden met toevoegingen van 13 en 5 verwijderingen
  1. 7 0
      mcs/class/corlib/System.Collections/ChangeLog
  2. 6 5
      mcs/class/corlib/System.Collections/Hashtable.cs

+ 7 - 0
mcs/class/corlib/System.Collections/ChangeLog

@@ -1,3 +1,10 @@
+2006-08-16  Miguel de Icaza  <[email protected]>
+
+	* Hashtable.cs (PutImpl): Do not access the table twice, only
+	once. 
+	
+	(TestPrime): optimize, take the sqrt out of the loop.
+
 2006-08-08  Duncan Mak  <[email protected]>
 
 	* ReadOnlyCollectionBase.cs (Count): Mark as virtual in

+ 6 - 5
mcs/class/corlib/System.Collections/Hashtable.cs

@@ -737,11 +737,10 @@ namespace System.Collections {
 			if (key == null)
 				throw new ArgumentNullException ("key", "null key");
 
-			uint size = (uint)this.table.Length;
-			if (this.inUse >= this.threshold) {
+			if (this.inUse >= this.threshold) 
 				this.Rehash ();
-				size = (uint)this.table.Length;
-			}
+
+			uint size = (uint)this.table.Length;
 
 			int h = this.GetHash (key) & Int32.MaxValue;
 			uint spot = (uint)h;
@@ -818,7 +817,9 @@ namespace System.Collections {
 		internal static bool TestPrime (int x)
 		{
 			if ((x & 1) != 0) {
-				for (int n = 3; n< (int)Math.Sqrt (x); n += 2) {
+				int top = (int)Math.Sqrt (x);
+				
+				for (int n = 3; n < top; n += 2) {
 					if ((x % n) == 0)
 						return false;
 				}