Alternative System.Lazy implementation (dotnet/coreclr#8963)
authorPaul Westcott <p.westcott@gmail.com>
Sat, 4 Mar 2017 03:14:02 +0000 (14:14 +1100)
committerJan Kotas <jkotas@microsoft.com>
Sat, 4 Mar 2017 03:14:02 +0000 (19:14 -0800)
commit9c0a2a989a0e6f0f27eeac1d41887427f385a461
treeb6db931f670e9341ebe4bc2bcfdc3fb95b53dda7
parent241982c1635ef58b4ce075be16ea026ac8176530
Alternative System.Lazy implementation (dotnet/coreclr#8963)

* Remove use of lock for PublicationOnly

This involves a little bit of trickery. In avoiding the lock we need to
go from m_implementation as PublicationOnly to null in a single step. We
can't do this though without another object, so we reuse out Lazy
object, which basically just spins its wheels until the value is ready.
This shouldn't be a very common scenerio (i.e. hitting that code path)
but it is possible.

* Minimize additional object creation

Storing factory in Lazy object, and passing Lazy as a parameter to
ILazyItem functions. This means that None & PublicationOnly now need no
creation of secondary object.

* Remove Func<T> for default constructor invoking

Fixing startup performance concerns

* Moved non-generic functionality out of Lazy

...and into a helper class

* Expression-bodied functions

Commit migrated from https://github.com/dotnet/coreclr/commit/2453adf1afba45dec79c6c643623b656702a17de
src/coreclr/src/mscorlib/src/System/Lazy.cs