@@ -6415,7 +6415,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
6415
6415
case TdsEnums.SQLUNIQUEID:
6416
6416
{
6417
6417
Debug.Assert(length == 16, "invalid length for SqlGuid type!");
6418
- value.SqlGuid = SqlTypeWorkarounds.SqlGuidCtor (unencryptedBytes, true); // doesn't copy the byte array
6418
+ value.SqlGuid = SqlTypeWorkarounds.ByteArrayToSqlGuid (unencryptedBytes);
6419
6419
break;
6420
6420
}
6421
6421
@@ -6436,7 +6436,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
6436
6436
unencryptedBytes = bytes;
6437
6437
}
6438
6438
6439
- value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor (unencryptedBytes, true); // doesn't copy the byte array
6439
+ value.SqlBinary = SqlTypeWorkarounds.ByteArrayToSqlBinary (unencryptedBytes);
6440
6440
break;
6441
6441
}
6442
6442
@@ -6661,7 +6661,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
6661
6661
}
6662
6662
else
6663
6663
{
6664
- value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); // doesn't copy the byte array
6664
+ value.SqlBinary = SqlTypeWorkarounds.ByteArrayToSqlBinary(b);
6665
6665
}
6666
6666
break;
6667
6667
@@ -6676,7 +6676,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
6676
6676
6677
6677
// Internally, we use Sqlbinary to deal with varbinary data and store it in
6678
6678
// SqlBuffer as SqlBinary value.
6679
- value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true );
6679
+ value.SqlBinary = SqlTypeWorkarounds.ByteArrayToSqlBinary(b );
6680
6680
6681
6681
// Extract the metadata from the payload and set it as the vector attributes
6682
6682
// in the SqlBuffer. This metadata is further used when constructing a SqlVector
@@ -7005,8 +7005,8 @@ internal TdsOperationStatus TryReadSqlValueInternal(SqlBuffer value, byte tdsTyp
7005
7005
{
7006
7006
return result;
7007
7007
}
7008
- value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); // doesn't copy the byte array
7009
-
7008
+
7009
+ value.SqlBinary = SqlTypeWorkarounds.ByteArrayToSqlBinary(b);
7010
7010
break;
7011
7011
}
7012
7012
@@ -7886,22 +7886,27 @@ internal byte[] SerializeSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)
7886
7886
7887
7887
// sign
7888
7888
if (d.IsPositive)
7889
+ {
7889
7890
bytes[current++] = 1;
7891
+ }
7890
7892
else
7893
+ {
7891
7894
bytes[current++] = 0;
7895
+ }
7892
7896
7893
- uint data1, data2, data3, data4;
7894
- SqlTypeWorkarounds.SqlDecimalExtractData(d, out data1, out data2, out data3, out data4);
7895
- byte[] bytesPart = SerializeUnsignedInt(data1, stateObj);
7897
+ Span<uint> data = stackalloc uint[4];
7898
+ SqlTypeWorkarounds.SqlDecimalWriteTdsValue(d, data);
7899
+
7900
+ byte[] bytesPart = SerializeUnsignedInt(data[0], stateObj);
7896
7901
Buffer.BlockCopy(bytesPart, 0, bytes, current, 4);
7897
7902
current += 4;
7898
- bytesPart = SerializeUnsignedInt(data2 , stateObj);
7903
+ bytesPart = SerializeUnsignedInt(data[1] , stateObj);
7899
7904
Buffer.BlockCopy(bytesPart, 0, bytes, current, 4);
7900
7905
current += 4;
7901
- bytesPart = SerializeUnsignedInt(data3 , stateObj);
7906
+ bytesPart = SerializeUnsignedInt(data[2] , stateObj);
7902
7907
Buffer.BlockCopy(bytesPart, 0, bytes, current, 4);
7903
7908
current += 4;
7904
- bytesPart = SerializeUnsignedInt(data4 , stateObj);
7909
+ bytesPart = SerializeUnsignedInt(data[3] , stateObj);
7905
7910
Buffer.BlockCopy(bytesPart, 0, bytes, current, 4);
7906
7911
7907
7912
return bytes;
@@ -7911,16 +7916,21 @@ internal void WriteSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)
7911
7916
{
7912
7917
// sign
7913
7918
if (d.IsPositive)
7919
+ {
7914
7920
stateObj.WriteByte(1);
7921
+ }
7915
7922
else
7923
+ {
7916
7924
stateObj.WriteByte(0);
7925
+ }
7926
+
7927
+ Span<uint> data = stackalloc uint[4];
7928
+ SqlTypeWorkarounds.SqlDecimalWriteTdsValue(d, data);
7917
7929
7918
- uint data1, data2, data3, data4;
7919
- SqlTypeWorkarounds.SqlDecimalExtractData(d, out data1, out data2, out data3, out data4);
7920
- WriteUnsignedInt(data1, stateObj);
7921
- WriteUnsignedInt(data2, stateObj);
7922
- WriteUnsignedInt(data3, stateObj);
7923
- WriteUnsignedInt(data4, stateObj);
7930
+ WriteUnsignedInt(data[0], stateObj);
7931
+ WriteUnsignedInt(data[1], stateObj);
7932
+ WriteUnsignedInt(data[2], stateObj);
7933
+ WriteUnsignedInt(data[3], stateObj);
7924
7934
}
7925
7935
7926
7936
private byte[] SerializeDecimal(decimal value, TdsParserStateObject stateObj)
0 commit comments