[Mono-list] ArrayList and CollectionBase bug fixes

Nick Drochak ndrochak@gol.com
Sun, 4 Nov 2001 17:41:43 +0900


Hi all,

I fixed a bug in ArrayList that was causing one of the tests for
CollectionBase to fail.  The "shift left" part of the remove procedure
had an "off by one" error.

At the same time I noticed a problem within CollectionBase.  The
RemoveAt() method was not calling the On*() hooks.

Below are the diff's...

Nick D.

Index: ArrayList.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.Collections/ArrayList.cs,v
retrieving revision 1.5
diff -u -r1.5 ArrayList.cs
--- ArrayList.cs        2001/11/04 03:15:53     1.5
+++ ArrayList.cs        2001/11/04 04:37:41
@@ -128,7 +128,7 @@
                                        }
                                } else {
                                        int numelts = count - startIndex
+ numshift;
-                                       for (int i = startIndex; i <
numelts; i++) {
+                                       for (int i = startIndex; i <=
numelts; i++) {
                                                dataArray[i] =
dataArray[i - numshift];
                                        }
                                        for (int i = count + numshift; i
< count; i++) {
Index: CollectionBase.cs
===================================================================
RCS file:
/cvs/public/mcs/class/corlib/System.Collections/CollectionBase.cs,v
retrieving revision 1.2
diff -u -r1.2 CollectionBase.cs
--- CollectionBase.cs   2001/08/07 16:59:34     1.2
+++ CollectionBase.cs   2001/11/04 04:37:41
@@ -27,7 +27,12 @@
                        OnClearComplete();
                }
                public virtual void RemoveAt (int index) {
+                       object objectToRemove;
+                       objectToRemove = InnerList[index];
+                       OnValidate(objectToRemove);
+                       OnRemove(index, objectToRemove);
                        InnerList.RemoveAt(index);
+                       OnRemoveComplete(index, objectToRemove);
                }

                // Protected Instance Constructors