MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:rburnett Date:May 15 2008 10:15pm
Subject:Connector/NET commit: r1298 - in branches/5.2: . MySql.Data/Provider/Source
View as plain text  
Modified:
   branches/5.2/CHANGES
   branches/5.2/MySql.Data/Provider/Source/datareader.cs
Log:
Increased the speed of MySqlDataReader.GetOrdinal dramatically by using a couple
  of hashes for lookups

Modified: branches/5.2/CHANGES
===================================================================
--- branches/5.2/CHANGES	2008-05-08 15:20:49 UTC (rev 1297)
+++ branches/5.2/CHANGES	2008-05-15 22:15:25 UTC (rev 1298)
@@ -1,3 +1,7 @@
+Version 5.2.3
+- Increased the speed of MySqlDataReader.GetOrdinal dramatically by using a couple
+  of hashes for lookups
+  
 Version 5.2.2 - 
 - Fixed profile provider that would throw an exception if you were updating
   a profile that already existed.

Modified: branches/5.2/MySql.Data/Provider/Source/datareader.cs
===================================================================
--- branches/5.2/MySql.Data/Provider/Source/datareader.cs	2008-05-08 15:20:49 UTC (rev 1297)
+++ branches/5.2/MySql.Data/Provider/Source/datareader.cs	2008-05-15 22:15:25 UTC (rev 1298)
@@ -24,6 +24,8 @@
 using System.Collections;
 using MySql.Data.Types;
 using System.Data.SqlTypes;
+using System.Collections.Generic;
+using System.Globalization;
 
 namespace MySql.Data.MySqlClient
 {
@@ -49,6 +51,8 @@
 		private int seqIndex;
 		private bool hasRead;
 		private bool nextResultDone;
+		private Hashtable fieldHashCS;
+		private Hashtable fieldHashCI;
 
 		/* 
 		 * Keep track of the connection in order to implement the
@@ -71,6 +75,8 @@
 			affectedRows = -1;
 			this.statement = statement;
 			nextResultDone = false;
+			fieldHashCS = new Hashtable();
+			fieldHashCI = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
 		}
 
 		#region Properties
@@ -536,13 +542,16 @@
 			if (!isOpen)
 				throw new Exception("No current query in data reader");
 
-			name = name.ToLower(System.Globalization.CultureInfo.InvariantCulture);
-			for (int i = 0; i < fields.Length; i++)
-			{
-				if (fields[i].ColumnName.ToLower(System.Globalization.CultureInfo.InvariantCulture) == name)
-					return i;
-			}
+			// first we try a quick hash lookup
+			object ordinal = fieldHashCS[name];
+			if (ordinal != null)
+				return (int)ordinal;
 
+			// ok that failed so we use our CI hash
+			ordinal = fieldHashCI[name];
+			if (ordinal != null)
+				return (int)ordinal;
+
 			// Throw an exception if the ordinal cannot be found.
 			throw new IndexOutOfRangeException("Could not find specified column in results");
 		}
@@ -844,9 +853,15 @@
 				}
 
 				fields = driver.ReadColumnMetadata((int)fieldCount);
+				fieldHashCS.Clear();
+				fieldHashCI.Clear();
 				values = new IMySqlValue[fields.Length];
 				for (int i = 0; i < fields.Length; i++)
+				{
+					fieldHashCS.Add(fields[i].ColumnName, i);
+					fieldHashCI.Add(fields[i].ColumnName, i);
 					values[i] = fields[i].GetValueObject();
+				}
 				hasRead = false;
 
 				uaFieldsUsed = new bool[fields.Length];

Thread
Connector/NET commit: r1298 - in branches/5.2: . MySql.Data/Provider/Sourcerburnett16 May