From 99a6d83c0b218137d20c6489c334e6ce78d6222e Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Thu, 20 Dec 2012 12:09:05 -0500 Subject: [PATCH] [corlib] Optimize System.Nullable.GetValueOrDefault(). Optimize System.Nullable.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.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 | 2 +- mcs/class/corlib/System/Nullable.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/external/ikvm b/external/ikvm index 08448c355b2..3db612102e0 160000 --- a/external/ikvm +++ b/external/ikvm @@ -1 +1 @@ -Subproject commit 08448c355b296bebff12b1210fc498594e6dabda +Subproject commit 3db612102e06332eebebd128cd06be68b03c2f0e diff --git a/mcs/class/corlib/System/Nullable.cs b/mcs/class/corlib/System/Nullable.cs index b8ac671d699..86a7bd7d4a4 100644 --- a/mcs/class/corlib/System/Nullable.cs +++ b/mcs/class/corlib/System/Nullable.cs @@ -140,7 +140,7 @@ namespace System public T GetValueOrDefault () { - return has_value ? value : default (T); + return value; } public T GetValueOrDefault (T defaultValue) -- 2.25.1