From 3e05aeb8382f7d7cf23460b1dda1052d203d8ad5 Mon Sep 17 00:00:00 2001 From: panoskj Date: Wed, 5 Oct 2022 12:07:35 +0300 Subject: [PATCH] TdsParserStateObject: Removed unnecessary casts. --- .../Data/SqlClient/TdsParserStateObject.cs | 14 +++++++------- .../Data/SqlClient/TdsParserStateObject.cs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs index d8c17386ea..e579500c84 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs @@ -916,7 +916,7 @@ internal bool TryReadPlpLength(bool returnPlpNullIfNull, out ulong lengthLeft) } else { - _longlenleft = (ulong)chunklen; + _longlenleft = chunklen; } } @@ -992,7 +992,7 @@ internal bool TryReadPlpBytes(ref byte[] buff, int offset, int len, out int tota if ((ulong)(buff?.Length ?? 0) != _longlen) { // if the buffer is null or the wrong length create one to use - buff = new byte[(int)Math.Min((int)_longlen, len)]; + buff = new byte[(Math.Min((int)_longlen, len))]; } } @@ -1086,12 +1086,12 @@ internal bool TrySkipLongBytes(long num) while (num > 0) { - int cbSkip = (int)Math.Min((long)int.MaxValue, num); + int cbSkip = (int)Math.Min(int.MaxValue, num); if (!TryReadByteArray(Span.Empty, cbSkip)) { return false; } - num -= (long)cbSkip; + num -= cbSkip; } return true; @@ -1367,7 +1367,7 @@ private bool OnTimeoutCore(int expectedState, int targetState, bool asyncClose = { if (!_attentionSent) { - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); // Grab a reference to the _networkPacketTaskSource in case it becomes null while we are trying to use it TaskCompletionSource source = _networkPacketTaskSource; @@ -1704,7 +1704,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error) { stateObj.SetTimeoutStateStopped(); Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point."); - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); if (!stateObj._attentionSent) { @@ -2680,7 +2680,7 @@ private Task WriteSni(bool canAccumulate) try { Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point."); - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); _bulkCopyWriteTimeout = true; SendAttention(); _parser.ProcessPendingAck(this); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs index 21ea221f2d..01312b80ed 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs @@ -1044,7 +1044,7 @@ internal bool TryReadPlpLength(bool returnPlpNullIfNull, out ulong lengthLeft) } else { - _longlenleft = (ulong)chunklen; + _longlenleft = chunklen; } } @@ -1110,7 +1110,7 @@ internal bool TryReadPlpBytes(ref byte[] buff, int offst, int len, out int total // If total length is known up front, allocate the whole buffer in one shot instead of realloc'ing and copying over each time if (buff == null && _longlen != TdsEnums.SQL_PLP_UNKNOWNLEN) { - buff = new byte[(int)Math.Min((int)_longlen, len)]; + buff = new byte[(Math.Min((int)_longlen, len))]; } if (_longlenleft == 0) @@ -1190,12 +1190,12 @@ internal bool TrySkipLongBytes(long num) while (num > 0) { - int cbSkip = (int)Math.Min((long)int.MaxValue, num); + int cbSkip = (int)Math.Min(int.MaxValue, num); if (!TryReadByteArray(Span.Empty, cbSkip)) { return false; } - num -= (long)cbSkip; + num -= cbSkip; } return true; @@ -1465,7 +1465,7 @@ private bool OnTimeoutCore(int expectedState, int targetState, bool asyncClose = { if (!_attentionSent) { - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); // Grab a reference to the _networkPacketTaskSource in case it becomes null while we are trying to use it TaskCompletionSource source = _networkPacketTaskSource; @@ -1826,7 +1826,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error) { stateObj.SetTimeoutStateStopped(); Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point."); - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); if (!stateObj._attentionSent) { @@ -2746,7 +2746,7 @@ private Task WriteSni(bool canAccumulate) try { Debug.Assert(_parser.Connection != null, "SqlConnectionInternalTds handler can not be null at this point."); - AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); + AddError(new SqlError(TdsEnums.TIMEOUT_EXPIRED, 0x00, TdsEnums.MIN_ERROR_CLASS, _parser.Server, _parser.Connection.TimeoutErrorInternal.GetErrorMessage(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT)); _bulkCopyWriteTimeout = true; SendAttention(); _parser.ProcessPendingAck(this);