Skip to content

Commit

Permalink
Do not clone empty arrays in CloneByteArray
Browse files Browse the repository at this point in the history
  • Loading branch information
vcsjones authored Oct 9, 2023
1 parent e9666c3 commit 63a375e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ internal static partial class Helpers
[return: NotNullIfNotNull(nameof(src))]
public static byte[]? CloneByteArray(this byte[]? src)
{
if (src == null)
return src switch
{
return null;
}

return (byte[])(src.Clone());
null => null,
{ Length: 0 } => src,
_ => (byte[])src.Clone(),
};
}

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

0 comments on commit 63a375e

Please sign in to comment.