Hi Miguel and Juan,
I've just noticed the commit to List.FindAll(). Attached is an (small)
optimization for the optimization:
- the resulting List<T> is built directly as an array which is later on
wrapped by a List<T> object. This eliminates the unnecessary overhead of
List.Add().
- the filling of the result array stops as soon as all found items are
processed. If there are no matches at the end of the original list, this
will give an small performance win.
The test-run of the resulting code ran fine and it should always be
faster than the version in svn.
May I commit (with a changelog entry of course)?
- Juraj
Index: List.cs
===================================================================
--- List.cs (revision 74697)
+++ List.cs (working copy)
@@ -246,13 +246,14 @@
}
}
- List <T> results = new List <T> (found);
+ T [] results = new T [found];
bitmask = 0x80000000;
ptr = bits;
- for (int i = 0; i < this._size; i++)
+ int j = 0;
+ for (int i = 0; i < this._size && j < found; i++)
{
if (((*ptr) & bitmask) == bitmask)
- results.Add (this._items [i]);
+ results [j++] = this._items [i];
bitmask = bitmask >> 1;
if (bitmask == 0)
@@ -262,7 +263,7 @@
}
}
- return results;
+ return new List <T> (results, found);
}
}
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list