Author: krasnov
Date: 2008-02-18 11:25:21 -0500 (Mon, 18 Feb 2008)
New Revision: 96069

Modified:
   trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
   
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
Log:
* WebConfigurationManager.cs: performance improvement, cached GetSection method

Modified: trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog   
2008-02-18 16:19:48 UTC (rev 96068)
+++ trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog   
2008-02-18 16:25:21 UTC (rev 96069)
@@ -1,3 +1,8 @@
+2008-02-18  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * WebConfigurationManager.cs: performance improvement, cached
+       GetSection method
+
 2008-02-07  Vladimir Krasnov  <[EMAIL PROTECTED]>
 
        * GlobalizationSection.cs: fixed GetSanitizedCulture, performance

Modified: 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
  2008-02-18 16:19:48 UTC (rev 96068)
+++ 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
  2008-02-18 16:25:21 UTC (rev 96069)
@@ -47,6 +47,7 @@
 #if !TARGET_J2EE
                static IInternalConfigConfigurationFactory configFactory;
                static Hashtable configurations = Hashtable.Synchronized (new 
Hashtable ());
+               static Hashtable sectionCache = new Hashtable 
(StringComparer.OrdinalIgnoreCase);
 #else
                const string AppSettingsKey = 
"WebConfigurationManager.AppSettings";
                static internal IInternalConfigConfigurationFactory 
configFactory
@@ -94,6 +95,23 @@
                                
AppDomain.CurrentDomain.SetData("WebConfigurationManager.configurations.initialized",
 true);
                        }
                }
+
+               static Hashtable sectionCache
+               {
+                       get
+                       {
+                               Hashtable sectionCache = (Hashtable) 
AppDomain.CurrentDomain.GetData ("sectionCache");
+                               if (sectionCache == null) {
+                                       sectionCache = new Hashtable 
(StringComparer.OrdinalIgnoreCase);
+                                       AppDomain.CurrentDomain.SetData 
("sectionCache", sectionCache);
+                               }
+                               return sectionCache;
+                       }
+                       set
+                       {
+                               AppDomain.CurrentDomain.SetData 
("sectionCache", value);
+                       }
+               }
 #endif
 
                static ArrayList extra_assemblies = null;
@@ -266,6 +284,10 @@
 
                public static object GetSection (string sectionName, string 
path)
                {
+                       object cachedSection = sectionCache [GetSectionCacheKey 
(sectionName, path)];
+                       if (cachedSection != null)
+                               return cachedSection;
+
                        _Configuration c = OpenWebConfiguration (path);
                        ConfigurationSection section = c.GetSection 
(sectionName);
 
@@ -275,26 +297,17 @@
 #if TARGET_J2EE
                        object value = get_runtime_object.Invoke (section, new 
object [0]);
                        if (String.CompareOrdinal ("appSettings", sectionName) 
== 0) {
-                               AppDomain appDomain = AppDomain.CurrentDomain;
-                               Hashtable settingsCache = (Hashtable) 
appDomain.GetData (AppSettingsKey);
-                               if (settingsCache == null) {
-                                       settingsCache = Hashtable.Synchronized 
(new Hashtable ());
-                                       appDomain.SetData (AppSettingsKey, 
settingsCache);
-                               }
-
-                               NameValueCollection collection = 
(NameValueCollection) settingsCache [c];
-
-                               if (collection == null) {
-                                       collection = new 
KeyValueMergedCollection (HttpContext.Current, (NameValueCollection) value);
-                                       settingsCache [c] = collection;
-                               }
-
+                               NameValueCollection collection;
+                               collection = new KeyValueMergedCollection 
(HttpContext.Current, (NameValueCollection) value);
                                value = collection;
                        }
 
+                       AddSectionToCache (GetSectionCacheKey (sectionName, 
path), value);
                        return value;
 #else
-                       return SettingsMappingManager.MapSection 
(get_runtime_object.Invoke (section, new object [0]));
+                       object value = SettingsMappingManager.MapSection 
(get_runtime_object.Invoke (section, new object [0]));
+                       AddSectionToCache (GetSectionCacheKey (sectionName, 
path), value);
+                       return value;
 #endif
                }
 
@@ -332,6 +345,25 @@
                internal static IInternalConfigConfigurationFactory 
ConfigurationFactory {
                        get { return configFactory; }
                }
+
+               static void AddSectionToCache (string key, object section)
+               {
+                       if (sectionCache [key] != null)
+                               return;
+
+                       Hashtable tmpTable = (Hashtable) sectionCache.Clone ();
+                       if (tmpTable [key] != null)
+                               return;
+
+                       tmpTable.Add (key, section);
+                       sectionCache = tmpTable;
+               }
+
+               static string GetSectionCacheKey (string sectionName, string 
path)
+               {
+                       return string.Concat (path, "/", sectionName);
+               }
+
                
 #region stuff copied from WebConfigurationSettings
 #if TARGET_J2EE

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to