Hello,
The attached patch reduces the amount of memory allocations in
FileSystemWatcher.RaiseEvent() and
MulticastDelegate.GetInvocationList().
See http://bugzilla.ximian.com/show_bug.cgi?id=81627 for more
information. The amount of allocated memory is reduced by almost one
third for the test program attached to the bug report.
Please review.
- Juraj
Index: corlib/System/ChangeLog
===================================================================
--- corlib/System/ChangeLog (revision 82267)
+++ corlib/System/ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2007-07-19 Juraj Skripsky <[EMAIL PROTECTED]>
+
+ * MulticastDelegate.cs (GetInvocationList): Reduce cloning, remove
+ unnecessary block.
+
2007-06-06 Miguel de Icaza <[EMAIL PROTECTED]>
* Int16.cs, UInt64.cs, SByte.cs, UInt16.cs, Byte.cs, Int32.cs,
Index: corlib/System/MulticastDelegate.cs
===================================================================
--- corlib/System/MulticastDelegate.cs (revision 82267)
+++ corlib/System/MulticastDelegate.cs (working copy)
@@ -106,18 +106,16 @@
// </summary>
public sealed override Delegate[] GetInvocationList ()
{
- MulticastDelegate d;
- d = (MulticastDelegate) this.Clone ();
+ // does the list only contain ourself?
+ if (prev == null)
+ return new Delegate [1] { this };
+
+ // walk the list backwards, connecting the links the other way
+ MulticastDelegate d = this;
for (d.kpm_next = null; d.prev != null; d = d.prev)
d.prev.kpm_next = d;
- if (d.kpm_next == null) {
- MulticastDelegate other = (MulticastDelegate) d.Clone ();
- other.prev = null;
- other.kpm_next = null;
- return new Delegate [1] { other };
- }
-
+ // walk the list, building the invocation list
ArrayList list = new ArrayList ();
for (; d != null; d = d.kpm_next) {
MulticastDelegate other = (MulticastDelegate) d.Clone ();
Index: System/System.IO/ChangeLog
===================================================================
--- System/System.IO/ChangeLog (revision 82267)
+++ System/System.IO/ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2007-07-19 Juraj Skripsky <[EMAIL PROTECTED]>
+
+ * FileSystemWatcher.ch (RaiseEvent): Invoke delegate directly, we don't
+ need the extra control provided by using GetInvocationList().
+
2006-11-01 Sebastien Pouliot <[EMAIL PROTECTED]>
* ErrorEventHandler.cs: Remove [Serializable] in NET_2_0.
Index: System/System.IO/FileSystemWatcher.cs
===================================================================
--- System/System.IO/FileSystemWatcher.cs (revision 82267)
+++ System/System.IO/FileSystemWatcher.cs (working copy)
@@ -371,19 +371,16 @@
return;
if (synchronizingObject == null) {
- Delegate [] delegates = ev.GetInvocationList ();
- if (evtype == EventType.RenameEvent) {
- foreach (RenamedEventHandler d in delegates){
- d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
- }
- } else if (evtype == EventType.ErrorEvent) {
- foreach (ErrorEventHandler d in delegates){
- d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
- }
- } else {
- foreach (FileSystemEventHandler d in delegates){
- d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
- }
+ switch (evtype) {
+ case EventType.RenameEvent:
+ ((RenamedEventHandler)ev).BeginInvoke (this, (RenamedEventArgs) arg, null, null);
+ break;
+ case EventType.ErrorEvent:
+ ((ErrorEventHandler)ev).BeginInvoke (this, (ErrorEventArgs) arg, null, null);
+ break;
+ case EventType.FileSystemEvent:
+ ((FileSystemEventHandler)ev).BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
+ break;
}
return;
}
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list