Skip to content

(Proposal) Inline the Lambda. #275

@AdamSpeight2008

Description

@AdamSpeight2008

Premise
Allow lambda function (in particularly LINQ) to rewritten by the compiler as inline version of the algorithm. No Closures, No Delegates

Syntax
This would be enable by prefixing the lambda with inline eg
inline (x,y)=> ;

Example

The foreach aspect of the pull request #209 could written via Aggregate.

int hash = Hash.Combine(_location.GetHashCode(), 
                       Hash.Combine(_severity.GetHashCode(), _warningLevel)); 

hash =  _messageArgs.Aggregate( hash, inline (_h, item)=> HashCode.Combine( _h, item) );
hash = HashCode.Combine( _descriptor, hash)
return hash;

would be rewritten as an inline implementation.

int hash = Hash.Combine(_location.GetHashCode(), 
                       Hash.Combine(_severity.GetHashCode(), _warningLevel)); 
/* Begin Inline (Aggregate) */
 var _h = hash;
 foreach(var item in _messageArgs)
 {
    HashCode.Combine( _h, item);
 }
hash = _h
/* End Inline ( Aggregate ) */

hash = HashCode.Combine( _descriptor, hash)
return hash;

Admittedly the produce code is slightly less efficient (an extra variable).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions