[corlib] Optimize System.Nullable<T>.GetValueOrDefault().
authorJonathan Pryor <jonpryor@vt.edu>
Thu, 20 Dec 2012 17:09:05 +0000 (12:09 -0500)
committerJonathan Pryor <jonpryor@vt.edu>
Thu, 20 Dec 2012 17:09:05 +0000 (12:09 -0500)
commit99a6d83c0b218137d20c6489c334e6ce78d6222e
tree5fddc6f93bb726d25092983254f92730642f26fa
parent2d917005cc80ce43b6b925bf90169a6288852acb
[corlib] Optimize System.Nullable<T>.GetValueOrDefault().

Optimize System.Nullable<T>.GetValueOrDefault().

See discussion at:
http://ericlippert.com/2012/12/20/nullable-micro-optimizations-part-one/

If a variable of nullable value type is initialized with the
default constructor then the [has_value] field will be its
default value, false, and the value field will be default(T).

Since we know that Nullable<T>.value will be the default value when
the default constructor has executed, we can return it directly
instead of checking the has_value field.
external/ikvm
mcs/class/corlib/System/Nullable.cs