@@ -56,9 +56,11 @@ public static unsafe int GetByteCount(this Encoding encoding, ReadOnlySpan<char>
5656 public static unsafe int GetBytes ( this Encoding encoding , ReadOnlySpan < char > chars , Span < byte > bytes )
5757 {
5858 fixed ( char * charsPtr = & MemoryMarshal . GetReference ( chars ) )
59- fixed ( byte * bytesPtr = & MemoryMarshal . GetReference ( bytes ) )
6059 {
61- return encoding . GetBytes ( charsPtr , chars . Length , bytesPtr , bytes . Length ) ;
60+ fixed ( byte * bytesPtr = & MemoryMarshal . GetReference ( bytes ) )
61+ {
62+ return encoding . GetBytes ( charsPtr , chars . Length , bytesPtr , bytes . Length ) ;
63+ }
6264 }
6365 }
6466#endif
@@ -67,11 +69,13 @@ public static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan<char> cha
6769 public static unsafe void Convert ( this Encoder encoder , ReadOnlySpan < char > chars , Span < byte > bytes , bool flush , out int charsUsed , out int bytesUsed , out bool completed )
6870 {
6971 fixed ( char * charsPtr = & MemoryMarshal . GetReference ( chars ) )
70- fixed ( byte * bytesPtr = & MemoryMarshal . GetReference ( bytes ) )
7172 {
72- // MemoryMarshal.GetNonNullPinnableReference is internal, so fake it by using an invalid but non-null pointer; this
73- // prevents Convert from throwing an exception when the output buffer is empty
74- encoder . Convert ( charsPtr , chars . Length , bytesPtr is null ? ( byte * ) 1 : bytesPtr , bytes . Length , flush , out charsUsed , out bytesUsed , out completed ) ;
73+ fixed ( byte * bytesPtr = & MemoryMarshal . GetReference ( bytes ) )
74+ {
75+ // MemoryMarshal.GetNonNullPinnableReference is internal, so fake it by using an invalid but non-null pointer; this
76+ // prevents Convert from throwing an exception when the output buffer is empty
77+ encoder . Convert ( charsPtr , chars . Length , bytesPtr is null ? ( byte * ) 1 : bytesPtr , bytes . Length , flush , out charsUsed , out bytesUsed , out completed ) ;
78+ }
7579 }
7680 }
7781
0 commit comments