Author: krasnov
Date: 2007-03-29 07:38:00 -0500 (Thu, 29 Mar 2007)
New Revision: 75132
Modified:
trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.jvm.cs
Log:
* TemplateControl.jvm.cs: performance improvement, added cache for methods and
events in user code
Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2007-03-29 12:15:47 UTC
(rev 75131)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2007-03-29 12:38:00 UTC
(rev 75132)
@@ -1,3 +1,8 @@
+2007-03-29 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * TemplateControl.jvm.cs: performance improvement, added cache for
+ methods and events in user code
+
2007-03-26 Marek Habersack <[EMAIL PROTECTED]>
* TemplateControl.cs: make local resources work with master
Modified: trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.jvm.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.jvm.cs
2007-03-29 12:15:47 UTC (rev 75131)
+++ trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.jvm.cs
2007-03-29 12:38:00 UTC (rev 75132)
@@ -157,36 +157,53 @@
return new LiteralControl (str);
}
+ sealed class EventMethodMap
+ {
+ public EventMethodMap (EventInfo Event, MethodInfo
Method, bool NoParameters)
+ {
+ this.Event = Event;
+ this.Method = Method;
+ this.NoParameters = NoParameters;
+ }
+
+ public readonly EventInfo Event;
+ public readonly MethodInfo Method;
+ public readonly bool NoParameters;
+ }
+
+ // This hashtable cashes methods and events found in user code
+ const string eventMethodCacheKey = "eventMethodCacheKey";
+ static Hashtable EventMethodCache
+ {
+ get { return (Hashtable)
AppDomain.CurrentDomain.GetData (eventMethodCacheKey); }
+ set { AppDomain.CurrentDomain.SetData
(eventMethodCacheKey, value); }
+ }
+
internal void WireupAutomaticEvents ()
{
- if (!SupportAutoEvents || !AutoEventWireup)
- return;
+ Type cacheKey = this.GetType ();
+ Hashtable eventMethodCache = EventMethodCache;
+ ArrayList eventMethodList = eventMethodCache == null ?
null : (ArrayList) eventMethodCache [cacheKey];
- Type thisType = typeof(TemplateControl);
- Type voidType = typeof (void);
- Type [] DefaultParams = new Type [] {
+ if (eventMethodList == null) {
+ eventMethodList = new ArrayList ();
+
+ if (!SupportAutoEvents || !AutoEventWireup)
+ return;
+
+ Type thisType = typeof (TemplateControl);
+ Type voidType = typeof (void);
+ Type [] DefaultParams = new Type [] {
typeof (object),
typeof (EventArgs) };
- foreach (string methodName in methodNames) {
- MethodInfo method;
- bool noParams = false;
- Type type = GetType ();
- do {
- method = type.GetMethod (methodName,
bflags, null, DefaultParams, null);
- if (method != null)
- break;
-
- type = type.BaseType;
- }
- while (type != thisType);
-
- if (method == null) {
- type = GetType ();
+ foreach (string methodName in methodNames) {
+ MethodInfo method;
+ bool noParams = false;
+ Type type = GetType ();
do {
- method = type.GetMethod
(methodName, bflags, null, NoParams, null);
+ method = type.GetMethod
(methodName, bflags, null, DefaultParams, null);
if (method != null) {
- noParams = true;
break;
}
@@ -194,10 +211,34 @@
}
while (type != thisType);
- if (method == null)
+ if (method == null) {
+ type = GetType ();
+ do {
+ method = type.GetMethod
(methodName, bflags, null, NoParams, null);
+ if (method != null) {
+ noParams = true;
+ break;
+ }
+
+ type = type.BaseType;
+ }
+ while (type != thisType);
+
+ if (method == null)
+ continue;
+ }
+ if (method.ReturnType != voidType)
continue;
- }
+ int pos = methodName.IndexOf ("_");
+ string eventName = methodName.Substring
(pos + 1);
+ EventInfo evt = GetType ().GetEvent
(eventName);
+ if (evt == null) {
+ /* This should never happen */
+ continue;
+ }
+
+ eventMethodList.Add (new EventMethodMap
(evt, method, noParams));
#if ONLY_1_1
if (method.DeclaringType != type) {
if (!method.IsPublic &&
!method.IsFamilyOrAssembly &&
@@ -205,25 +246,21 @@
continue;
}
#endif
+ }
+ // We copy to not lock
- if (method.ReturnType != voidType)
- continue;
+ Hashtable newEventMethodCache =
eventMethodCache == null ? new Hashtable () : (Hashtable)
eventMethodCache.Clone ();
+ newEventMethodCache [cacheKey] =
eventMethodList;
+ EventMethodCache = newEventMethodCache;
+ }
- int pos = methodName.IndexOf ("_");
- string eventName = methodName.Substring (pos +
1);
- EventInfo evt = GetType ().GetEvent (eventName);
- if (evt == null) {
- /* This should never happen */
- continue;
+ foreach (EventMethodMap eventMethod in eventMethodList)
{
+ if (eventMethod.NoParameters) {
+ NoParamsInvoker npi = new
NoParamsInvoker (this, eventMethod.Method);
+ eventMethod.Event.AddEventHandler
(this, npi.FakeDelegate);
}
-
- if (noParams) {
- NoParamsInvoker npi = new
NoParamsInvoker (this, method);
- evt.AddEventHandler (this,
npi.FakeDelegate);
- }
else {
- evt.AddEventHandler (this,
Delegate.CreateDelegate (
- typeof (EventHandler),
this, method));
+ eventMethod.Event.AddEventHandler
(this, Delegate.CreateDelegate (typeof (EventHandler), this,
eventMethod.Method));
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches