Author: krasnov
Date: 2008-02-18 11:27:06 -0500 (Mon, 18 Feb 2008)
New Revision: 96070
Modified:
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
Log:
merge -r96068:96069
Modified:
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
===================================================================
---
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
2008-02-18 16:25:21 UTC (rev 96069)
+++
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
2008-02-18 16:27:06 UTC (rev 96070)
@@ -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:
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
===================================================================
---
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
2008-02-18 16:25:21 UTC (rev 96069)
+++
branches/mainsoft/gh2.2/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
2008-02-18 16:27:06 UTC (rev 96070)
@@ -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;
@@ -258,7 +276,7 @@
return null;
}
}
-
+
public static object GetSection (string sectionName)
{
return GetSection (sectionName, GetCurrentPath
(HttpContext.Current));
@@ -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 - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches