[Mono-bugs] [Bug 608195] New: Enumerable.Reverse should be lazier

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon May 24 04:15:07 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=608195

http://bugzilla.novell.com/show_bug.cgi?id=608195#c0


           Summary: Enumerable.Reverse should be lazier
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Kubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Core
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: matthew.flaschen at gatech.edu
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Enumerable.Reverse is not lazy.  It accesses the original IEnumerable before
this is actually required.  However, the MSDN docs
(http://msdn.microsoft.com/en-us/library/bb358497%28v=VS.100%29.aspx) say,
"This method is implemented by using deferred execution. The immediate return
value is an object that stores all the information that is required to perform
the action. The query represented by this method is not executed until the
object is enumerated either by calling its GetEnumerator method directly."

The specified behavior has obvious benefits.  If the source IEnumerable is
backed by a database, it will not be accessed until required.   If you call it
on an excessively large collection (per the example), you will not run out of
memory unless you call GetEnumerator.

The current implementation creates a List<TSource> then passes it to an
iterator-generator method, CreateReverseIterator.  By simply merging them into
a single iterator-generator method, Reverse itself, we can get the desired
laziness.

Steps to reproduce the problem:
1. 
IEnumerable<int> reversedInts = Enumerable.Range(0, int.MaxValue).Reverse();

Actual Results:

Mono attempts to use 8GB of memory.

Expected Results:

Mono does not access the original IEnumerable unless you call
reversedInts.GetEnumerator.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list