2008-06-30 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2008 22:04:14 +0000 (22:04 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2008 22:04:14 +0000 (22:04 -0000)
* SqlDataReader.cs: Allocate 'schemaTable' lazily.
(GetSchemaValue): Avoid some hash table lookups

svn path=/trunk/mcs/; revision=106932

mcs/class/System.Data/System.Data.SqlClient/ChangeLog
mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs

index 58e380194fca43f7fd51ff0138a24ad69b9b227a..c07c93d6a021ed66d3613cb3698e26bdae3554a5 100644 (file)
@@ -1,3 +1,8 @@
+2008-06-30  Zoltan Varga  <vargaz@gmail.com>
+
+       * SqlDataReader.cs: Allocate 'schemaTable' lazily. 
+       (GetSchemaValue): Avoid some hash table lookups
+
 2008-06-27  Zoltan Varga  <vargaz@gmail.com>
 
        * SqlDataReader.cs (ConstructSchemaTable): Avoid unneccessary reflection calls.
index 3e4e7ab0c14087325e73a4ba2431268b182d51d2..93a1a5fdb22b2a84bec02a9c76f99d8a391d4205 100644 (file)
@@ -81,7 +81,6 @@ namespace System.Data.SqlClient
                        haveRead = false;
                        readResultUsed = false;
                        this.command = command;
-                       schemaTable = ConstructSchemaTable ();
                        resultsRead = 0;
                        fieldCount = 0;
                        isClosed = false;
@@ -236,7 +235,8 @@ namespace System.Data.SqlClient
                {
                        if (!disposed) {
                                if (disposing) {
-                                       schemaTable.Dispose ();
+                                       if (schemaTable != null)
+                                               schemaTable.Dispose ();
                                        Close ();
                                        command = null;
                                }
@@ -459,6 +459,8 @@ namespace System.Data.SqlClient
 #endif // NET_2_0
                Type GetFieldType (int i)
                {
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
                        if (i < 0 || i >= schemaTable.Rows.Count)
                                throw new IndexOutOfRangeException ();
                        return (Type) schemaTable.Rows[i]["DataType"];
@@ -540,6 +542,8 @@ namespace System.Data.SqlClient
 #endif // NET_2_0
                string GetName (int i)
                {
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
                        return (string) schemaTable.Rows[i]["ColumnName"];
                }
 
@@ -549,6 +553,8 @@ namespace System.Data.SqlClient
 #endif // NET_2_0
                int GetOrdinal (string name)
                {
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
                        foreach (DataRow schemaRow in schemaTable.Rows)
                                if (((string) schemaRow ["ColumnName"]).Equals (name))
                                        return (int) schemaRow ["ColumnOrdinal"];
@@ -566,6 +572,9 @@ namespace System.Data.SqlClient
                {
                        ValidateState ();
 
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
+
                        if (schemaTable.Rows != null && schemaTable.Rows.Count > 0)
                                return schemaTable;
 
@@ -775,9 +784,11 @@ namespace System.Data.SqlClient
 
                private static object GetSchemaValue (TdsDataColumn schema, object key)
                {
-                       if (schema.ContainsKey (key) && schema [key] != null)
-                               return schema [key];
-                       return DBNull.Value;
+                       object val = schema [key];
+                       if (val != null)
+                               return val;
+                       else
+                               return DBNull.Value;
                }
 
                public
@@ -960,6 +971,9 @@ namespace System.Data.SqlClient
 #endif
                object GetSqlValue (int i)
                {
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
+
                        SqlDbType type = (SqlDbType) (schemaTable.Rows [i]["ProviderType"]);
                        object value = GetValue (i);
 
@@ -1045,6 +1059,9 @@ namespace System.Data.SqlClient
 #endif
                int GetSqlValues (object[] values)
                {
+                       if (schemaTable == null)
+                               schemaTable = ConstructSchemaTable ();
+
                        int count = 0;
                        int columnCount = schemaTable.Rows.Count;
                        int arrayCount = values.Length;
@@ -1165,7 +1182,7 @@ namespace System.Data.SqlClient
                                command.GetOutputParameters ();
                        else {
                                //new schema
-                               schemaTable = ConstructSchemaTable ();
+                               schemaTable = null;
                                GetSchemaTable ();
                        }