Alternative System.Lazy implementation (#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)
commit2453adf1afba45dec79c6c643623b656702a17de
tree4b3ce314984d6d041801d4f5c62311aca66af03f
parent3834e6b27cbd32ebb7433e6a15f320c77c3074c6
Alternative System.Lazy implementation (#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
src/mscorlib/src/System/Lazy.cs