Skip to content

Commit cf2659e

Browse files
committed
Use 'scoped' to avoid redundant check.
1 parent 72af1a7 commit cf2659e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/MySqlConnector/Utilities/Utility.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ public static RSAParameters GetRsaParameters(string key)
138138
var keyChars = key.AsSpan()[keyStartIndex..keyEndIndex];
139139
var bufferLength = keyChars.Length / 4 * 3;
140140
byte[]? buffer = null;
141-
Span<byte> bufferBytes = bufferLength <= 1024 ? stackalloc byte[bufferLength] : default;
141+
scoped Span<byte> bufferBytes;
142142
if (bufferLength > 1024)
143-
{
144-
buffer = ArrayPool<byte>.Shared.Rent(bufferLength);
145-
bufferBytes = buffer.AsSpan();
146-
}
143+
bufferBytes = buffer = ArrayPool<byte>.Shared.Rent(bufferLength);
144+
else
145+
bufferBytes = stackalloc byte[bufferLength];
147146
try
148147
{
149148
if (!System.Convert.TryFromBase64Chars(keyChars, bufferBytes, out var bytesWritten))

0 commit comments

Comments
 (0)