[Mono-devel-list] patch for generic List
Ben Maurer
bmaurer at ximian.com
Tue Jan 4 15:47:14 EST 2005
On Wed, 2005-01-05 at 05:10 +0900, Atsushi Eno wrote:
> @@ -48,11 +49,11 @@
>
> const int DefaultCapacity = 4;
>
> - public List ()
> + public List () : this (DefaultCapacity)
> {
> }
>
> - public List (IEnumerable <T> collection)
> + public List (IEnumerable <T> collection) : this()
No. These are incorrect. The default List <T> ctor creates *NO* array on
purpose. Many times, people will create a list and never add anything to
it. Thus, I am allocating the list lazily. The other methods account for
that.
> - [MonoTODO ("PERFORMANCE: fix if it is an IList <T>")]
> public void AddRange(IEnumerable<T> collection)
> {
> - foreach (T t in collection)
> - Add (t);
> + InsertRange (size, collection);
> }
Won't inserting here throw an exception, as !(size < size)
> + #region Enumerator <T>
Not needed. This is already code folded by any editor.
> public struct Enumerator <T> : IEnumerator <T>, IEnumerator, IDisposable {
> const int NOT_STARTED = -2;
>
> @@ -548,6 +590,80 @@
> }
>
> }
> + #endregion
> +
> + #region ReadOnlyList <T>
Ditto.
Btw, I really need NUnit tests for this class ;-). I know I should have
written them. But this would be a good time to get started.
-- Ben
More information about the Mono-devel-list
mailing list