Author: andrews
Date: 2006-11-07 09:01:58 -0500 (Tue, 07 Nov 2006)
New Revision: 67455
Modified:
trunk/mcs/class/System/System.ComponentModel/ChangeLog
trunk/mcs/class/System/System.ComponentModel/EventHandlerList.cs
Log:
Implement event handler list according to MS definition
Modified: trunk/mcs/class/System/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/ChangeLog 2006-11-07
13:57:10 UTC (rev 67454)
+++ trunk/mcs/class/System/System.ComponentModel/ChangeLog 2006-11-07
14:01:58 UTC (rev 67455)
@@ -1,3 +1,10 @@
+2006-10-05 Andrew Skiba <[EMAIL PROTECTED]>
+
+ * EventHandlerList.cs: Implement event handler list according to MS
+ definition. No hash table, just a simple list with good performance
+ for a small number of events (<20) and worse performance when number
+ of events is bigger (patch by [EMAIL PROTECTED]).
+
2006-10-29 Alexander Olk <[EMAIL PROTECTED]>
* ComponentResourceManager.cs: Make ApplyResources work.
Modified: trunk/mcs/class/System/System.ComponentModel/EventHandlerList.cs
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/EventHandlerList.cs
2006-11-07 13:57:10 UTC (rev 67454)
+++ trunk/mcs/class/System/System.ComponentModel/EventHandlerList.cs
2006-11-07 14:01:58 UTC (rev 67455)
@@ -46,14 +46,13 @@
public EventHandlerList ()
{
+ head = null;
}
public Delegate this [object key] {
get {
- if (table == null)
- return null;
-
- return table [key] as Delegate;
+ ListNode entry = FindEntry (key);
+ return entry == null ? null : entry.value;
}
set {
@@ -63,28 +62,54 @@
public void AddHandler (object key, Delegate value)
{
- if (table == null)
- table = new Hashtable ();
-
- Delegate prev = table [key] as Delegate;
- prev = Delegate.Combine (prev, value);
- table [key] = prev;
+ ListNode entry = FindEntry (key);
+ if (entry == null) {
+ head = new ListNode (key, value, head);
+ return;
+ }
+ entry.value = Delegate.Combine (entry.value, value);
}
public void RemoveHandler (object key, Delegate value)
{
- if (table == null)
+ ListNode entry = FindEntry (key);
+ if (entry == null)
return;
- Delegate prev = table [key] as Delegate;
- prev = Delegate.Remove (prev, value);
- table [key] = prev;
+ entry.value = Delegate.Remove (entry.value, value);
}
public void Dispose ()
{
- table = null;
+ head = null;
}
+ private ListNode FindEntry (object key)
+ {
+ if (key == null)
+ throw new ArgumentNullException ("key",
"Attempted lookup for a null key.");
+
+ for (ListNode entry = head; entry != null; entry =
entry.next)
+ if (key == entry.key)
+ return entry;
+ return null;
+ }
+
+ [Serializable]
+ private class ListNode
+ {
+ public object key;
+ public Delegate value;
+ public ListNode next;
+ public ListNode (object key, Delegate value, ListNode
next)
+ {
+ this.key = key;
+ this.value = value;
+ this.next = next;
+ }
+ }
+
+ private ListNode head;
+
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches