@@ -51,8 +51,10 @@ public void Decrypt(ReadOnlySpan<char> ciphertext, Span<char> plaintext, out int
51
51
if ( start < end && ( end - start ) % 2 == 0 )
52
52
{
53
53
var span = ciphertext [ start ..end ] ;
54
- var bytes = Convert . FromHexString ( span ) ;
55
- writtenPosition += Encoding . GetChars ( bytes , plaintext ) ;
54
+ var bytesLength = span . Length / 2 ;
55
+ Span < byte > bytesBuffer = bytesLength < 1024 ? stackalloc byte [ bytesLength ] : new byte [ bytesLength ] ;
56
+ Convert . FromHexString ( span , bytesBuffer , out _ , out _ ) ;
57
+ writtenPosition += Encoding . GetChars ( bytesBuffer , plaintext ) ;
56
58
}
57
59
58
60
plaintext [ writtenPosition ++ ] = ch ;
@@ -63,8 +65,10 @@ public void Decrypt(ReadOnlySpan<char> ciphertext, Span<char> plaintext, out int
63
65
if ( start < end && ( end - start ) % 2 == 0 )
64
66
{
65
67
var span = ciphertext [ start ..end ] ;
66
- var bytes = Convert . FromHexString ( span ) ;
67
- writtenPosition += Encoding . GetChars ( bytes , plaintext ) ;
68
+ var bytesLength = span . Length / 2 ;
69
+ Span < byte > bytesBuffer = bytesLength < 1024 ? stackalloc byte [ bytesLength ] : new byte [ bytesLength ] ;
70
+ Convert . FromHexString ( span , bytesBuffer , out _ , out _ ) ;
71
+ writtenPosition += Encoding . GetChars ( bytesBuffer , plaintext ) ;
68
72
}
69
73
70
74
written = writtenPosition ;
0 commit comments