2008-06-26 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Fri, 27 Jun 2008 00:44:55 +0000 (00:44 -0000)
committerZoltan Varga <vargaz@gmail.com>
Fri, 27 Jun 2008 00:44:55 +0000 (00:44 -0000)
* nBrowser/Node.cs nBrowser/Result.cs: Avoid looking up adapter types names for
every request in every assembly.

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

mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
mcs/class/System.Web/System.Web.Configuration_2.0/nBrowser/Node.cs
mcs/class/System.Web/System.Web.Configuration_2.0/nBrowser/Result.cs

index 2843b50e51fee2054692701d92170d32f2b0fb1c..e18b4f4c84531091f161f81aec1df176a73c7afc 100644 (file)
@@ -1,3 +1,8 @@
+2008-06-26  Zoltan Varga  <vargaz@gmail.com>
+
+       * nBrowser/Node.cs nBrowser/Result.cs: Avoid looking up adapter types names for
+       every request in every assembly.
+
 2008-05-22  Marek Habersack  <mhabersack@novell.com>
 
        * WebConfigurationHost.cs: changed CreateDeprecatedConfigContext
index 7e47eb20e164a8163d6b8c097952d2493061ee8f..96aa61087ae580662fe4cc55c7f3f11df8635900 100644 (file)
@@ -128,6 +128,7 @@ namespace System.Web.Configuration.nBrowser
                private Identification[] Capture;
                private System.Collections.Specialized.NameValueCollection Capabilities;
                private System.Collections.Specialized.NameValueCollection Adapter;
+               private Type[] AdapterControlTypes, AdapterTypes;
                private System.Collections.Generic.List<string> ChildrenKeys;
                private System.Collections.Generic.List<string> DefaultChildrenKeys;
                private System.Collections.Generic.SortedList<string, nBrowser.Node> Children;
@@ -331,6 +332,9 @@ namespace System.Web.Configuration.nBrowser
                                        Adapter[controlType] = adapterType;
                                }
                        }
+
+                       AdapterControlTypes = null;
+                       AdapterTypes = null;
                }
 
                /// <summary>
@@ -397,6 +401,8 @@ namespace System.Web.Configuration.nBrowser
                        Capture = null;
                        Capabilities = null;
                        Adapter = null;
+                       AdapterControlTypes = null;
+                       AdapterTypes = null;
                        if (string.Compare(this.xmlNode.Name, "browser", true, System.Globalization.CultureInfo.CurrentCulture) == 0)
                        {
                                this.NameType = NodeType.Browser;
@@ -505,7 +511,21 @@ namespace System.Web.Configuration.nBrowser
                                DefaultChildrenKeys.Remove(child.Id);
                        }
                }
-               
+                               
+               private Type FindType(string typeName)
+               {
+                       foreach (System.Reflection.Assembly a in System.AppDomain.CurrentDomain.GetAssemblies())
+                       {
+                               string fullTypeName = typeName + "," + a.FullName;
+                               Type t = System.Type.GetType(fullTypeName); // case-sensitive
+                               if (t != null)
+                                       return t;
+                               t = System.Type.GetType(fullTypeName, false, true); // case-insensitive
+                               if (t != null)
+                                       return t;
+                       }
+                       throw new TypeLoadException(typeName);
+               }
                
                /// <summary>
                /// 
@@ -542,9 +562,21 @@ namespace System.Web.Configuration.nBrowser
                        //----------------------------------------------------------------------
                        if (Adapter != null)
                        {
+                               /* Lookup the types and store them for future use */
+                               if (AdapterControlTypes == null)
+                                       AdapterControlTypes = new Type [Adapter.Count];
+                               if (AdapterTypes == null)
+                                       AdapterTypes = new Type [Adapter.Count];
+                               for (int i = 0;i <= Adapter.Count - 1;i++) {
+                                       if (AdapterControlTypes [i] == null)
+                                               AdapterControlTypes [i] = FindType (Adapter.GetKey (i));
+                                       if (AdapterTypes [i] == null)
+                                               AdapterTypes [i] = FindType (Adapter [i]);
+                               }
+
                                for (int i = 0;i <= Adapter.Count - 1;i++)
                                {
-                                       result.AddAdapter(Adapter.GetKey(i), Adapter[i]);
+                                       result.AddAdapter(AdapterControlTypes [i], AdapterTypes [i]);
                                }
                        }
 
@@ -696,7 +728,7 @@ namespace System.Web.Configuration.nBrowser
                        {
                                for (int i = 0;i <= Adapter.Count - 1;i++)
                                {
-                                       result.AddAdapter(Adapter.GetKey(i), Adapter[i]);
+                                       result.AddAdapter(AdapterControlTypes [i], AdapterTypes [i]);
                                }
                        }
                        //----------------------------------------------------------------------
index 4b7450f9a5760329959fc34a02b6754cc0ddde29..ee8335699f1234ec21c8d0865978ce3886df79e7 100644 (file)
@@ -54,28 +54,11 @@ namespace System.Web.Configuration.nBrowser
                /// </summary>
                /// <param name="controlTypeName"></param>
                /// <param name="adapterTypeName"></param>
-               internal void AddAdapter(string controlTypeName, string adapterTypeName)
+               internal void AddAdapter(Type controlType, Type adapterType)
                {
-                       Type controlType = FindType(controlTypeName);
-                       Type adapterType = FindType(adapterTypeName);
                        AdapterTypeMap[controlType] = adapterType;
                }
                
-               private Type FindType(string typeName)
-               {
-                       foreach (System.Reflection.Assembly a in System.AppDomain.CurrentDomain.GetAssemblies())
-                       {
-                               string fullTypeName = typeName + "," + a.FullName;
-                               Type t = System.Type.GetType(fullTypeName); // case-sensitive
-                               if (t != null)
-                                       return t;
-                               t = System.Type.GetType(fullTypeName, false, true); // case-insensitive
-                               if (t != null)
-                                       return t;
-                       }
-                       throw new TypeLoadException(typeName);
-               }
-               
                /// <summary>
                /// 
                /// </summary>