Skip to content

Commit

Permalink
For perf, avoid calling ReboxFromNullable when not necessary part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
steveharter committed May 6, 2022
1 parent 55a4f95 commit c7bee67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,17 @@ internal bool CheckValue(
value = binder.ChangeType(value, this, culture);
if (IsInstanceOfType(value))
{
copyBack = ParameterCopyBackAction.Copy;
if (IsNullableOfT)
{
// Pass as a true boxed Nullable<T>, not as a T or null.
value = RuntimeMethodHandle.ReboxToNullable(value, this);
copyBack = ParameterCopyBackAction.CopyNullable;
}
else
{
copyBack = ParameterCopyBackAction.Copy;
}

return IsValueType; // Note the call to IsValueType, not the variable.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr,
if (val != null)
{
RuntimeType fieldType = (RuntimeType)FieldType;
bool _ = false;
ParameterCopyBackAction _ = default;

if (!ReferenceEquals(val.GetType(), fieldType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1648,15 +1648,15 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated)
/// <returns>Not yet implemented in Mono: True if the value should be considered a value type, False otherwise</returns>
internal bool CheckValue(
ref object? value,
ref bool copyBack,
ref ParameterCopyBackAction copyBack,
Binder? binder,
CultureInfo? culture,
BindingFlags invokeAttr)
{
// Already fast-pathed by the caller.
Debug.Assert(!ReferenceEquals(value?.GetType(), this));

copyBack = true;
copyBack = ParameterCopyBackAction.Copy;

CheckValueStatus status = TryConvertToType(ref value);
if (status == CheckValueStatus.Success)
Expand Down

0 comments on commit c7bee67

Please sign in to comment.