[Mono-dev] Trivial Enumerable Optimizations

Avery Pennarun apenwarr at gmail.com
Fri May 9 08:53:58 EDT 2008

On 5/9/08, Jonathan Pryor <jonpryor at vt.edu> wrote:
>            catch {
>                // ignore; collection has > int.MaxValue elements,
>                // so count manually below.
>            }
>  This will suffer an obvious performance penalty if the collection has
>  over int.MaxValue elements (assuming .Count throws an exception when
>  that happens), but as most (currently all?) collections will have less
>  than int.MaxValue elements, this should be a performance win.

Hmm, are you sure you really want to count them all manually when
there are greater than 2 billion elements in the data structure?  If I
was programming an app that used such a large array, I think I'd
rather just get a "too large/unimplemented" exception than have my
program go from O(1) to O(n) (at best), with a huge n, as soon as I
crossed a particular length threshold.  It's much easier to debug an
exception than a near-infinite loop...


More information about the Mono-devel-list mailing list