Skip to content

Commit

Permalink
Perf | avoid boxing of SqlGuid in SqlBuffer (dotnet#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbit committed Jan 19, 2024
1 parent b460fd0 commit 9602271
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5504,7 +5504,7 @@ internal static object GetNullSqlValue(SqlBuffer nullVal, SqlMetaDataPriv md, Sq
break;

case SqlDbType.UniqueIdentifier:
nullVal.SqlGuid = SqlGuid.Null;
nullVal.SetToNullOfType(SqlBuffer.StorageType.SqlGuid);
break;

case SqlDbType.Bit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6310,7 +6310,7 @@ internal static object GetNullSqlValue(
break;

case SqlDbType.UniqueIdentifier:
nullVal.SqlGuid = SqlGuid.Null;
nullVal.SetToNullOfType(SqlBuffer.StorageType.SqlGuid);
break;

case SqlDbType.Bit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ private static void GetNullOutputParameterSmi(SmiMetaData metaData, SqlBuffer ta
// special case SqlBinary, 'cause tds parser never sets SqlBuffer to null, just to empty!
targetBuffer.SqlBinary = SqlBinary.Null;
}
else if (SqlBuffer.StorageType.SqlGuid == stype)
{
targetBuffer.SqlGuid = SqlGuid.Null;
}
else
{
targetBuffer.SetToNullOfType(stype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal struct Storage
private bool _isNull;
private StorageType _type;
private Storage _value;
private object _object; // String, SqlBinary, SqlCachedBuffer, SqlGuid, SqlString, SqlXml
private object _object; // String, SqlBinary, SqlCachedBuffer, SqlString, SqlXml

internal SqlBuffer()
{
Expand Down Expand Up @@ -815,14 +815,17 @@ internal SqlGuid SqlGuid
}
else if (StorageType.SqlGuid == _type)
{
return IsNull ? SqlGuid.Null : (SqlGuid)_object;
return IsNull ? SqlGuid.Null : new SqlGuid(_value._guid);
}
return (SqlGuid)SqlValue; // anything else we haven't thought of goes through boxing.
}
set
{
Debug.Assert(IsEmpty, "setting value a second time?");
_object = value;
if (!value.IsNull)
{
_value._guid = value.Value;
}
_type = StorageType.SqlGuid;
_isNull = value.IsNull;
}
Expand Down

0 comments on commit 9602271

Please sign in to comment.