8000 Avoid closures due to implementations in local functions · Issue #906 · morelinq/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Avoid closures due to implementations in local functions #906
Closed
@viceroypenguin

Description

@viceroypenguin

Currently, most operators are implemented as such:

public static IEnumerator<TSource> Operator<TSource>(this IEnumerable<TSource> source, ...)
{
   // guard statements
   return _();

   _()
   {
      yield return source.First();
      yield break;
   }
}

A better implementation would be the following:

public static IEnumerator<TSource> Operator<TSource>(this IEnumerable<TSource> source, ...)
{
   // guard statements
   return _(source, ...);

   static _(IEnumerable<TSource> source, ...)
   {
      yield return source.First();
      yield break;
   }
}

With the current implementation, the host method must create a closure class before even doing guard statements, copy parameters, and then call a method on that closure class. This means that there are two closure classes: one for the parameters, and one for the enumerator.

Switching to passing the parameters into the iterator method means that only one closure class has to be created, the one for the enumerator; the parameters will be held by that class. This should simplify and improve the IL, the JIT, and the output JIT-ted code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0