Skip to content

Commit 63a375e

Browse files
authored
Do not clone empty arrays in CloneByteArray
1 parent e9666c3 commit 63a375e

File tree

1 file changed

+5
-5
lines changed
  • src/libraries/Common/src/System/Security/Cryptography

1 file changed

+5
-5
lines changed

src/libraries/Common/src/System/Security/Cryptography/Helpers.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ internal static partial class Helpers
4545
[return: NotNullIfNotNull(nameof(src))]
4646
public static byte[]? CloneByteArray(this byte[]? src)
4747
{
48-
if (src == null)
48+
return src switch
4949
{
50-
return null;
51-
}
52-
53-
return (byte[])(src.Clone());
50+
null => null,
51+
{ Length: 0 } => src,
52+
_ => (byte[])src.Clone(),
53+
};
5454
}
5555

5656
internal static bool TryCopyToDestination(this ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)

0 commit comments

Comments
 (0)