[Mono-dev] Trivial Enumerable Optimizations

Jonathan Pryor jonpryor at vt.edu
Fri May 9 22:16:47 EDT 2008


On Fri, 2008-05-09 at 17:05 -0400, Miguel de Icaza wrote:
> The problem is that there is no such rule that states that c.Count will
> throw an exception if it has more than certain number of elements.

Indeed.  This is something that we should take to ECMA and attempt to
standardize, as at some point someone will call ICollection<T>.Count
when a collection contains > int.MaxValue elements.  Saying "don't do
that" and/or "the results are undefined" are not particularly appealing
options.

(This is in fact already possible *now* with
System.Collections.Generic.LinkedList<T>, which stores count in a `uint'
which is unconditionally incremented within Add(), so you can see *both*
"negative" Count values after int.MaxValue+1 Add()s and a wrap-around to
0 after uint.MaxValue+1 Add()s.  I'd love to "fix" this, but having a
sense of what the correct fix is would be needed.  Should Count throw an
exception?  If so what type?  etc., etc.)

 - Jon




More information about the Mono-devel-list mailing list