|
5 | 5 | using System.Runtime.Serialization; |
6 | 6 | using System.Text; |
7 | 7 | using System; |
| 8 | +using System.Runtime.InteropServices; |
8 | 9 |
|
9 | 10 | namespace System.Text |
10 | 11 | { |
@@ -66,13 +67,8 @@ public override unsafe int GetCharCount(byte[] bytes, int index, int count, bool |
66 | 67 | throw new ArgumentOutOfRangeException(nameof(bytes), |
67 | 68 | SR.ArgumentOutOfRange_IndexCountBuffer); |
68 | 69 |
|
69 | | - |
70 | | - // Avoid null fixed problem |
71 | | - if (bytes.Length == 0) |
72 | | - bytes = new byte[1]; |
73 | | - |
74 | 70 | // Just call pointer version |
75 | | - fixed (byte* pBytes = &bytes[0]) |
| 71 | + fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes)) |
76 | 72 | return GetCharCount(pBytes + index, count, flush); |
77 | 73 | } |
78 | 74 |
|
@@ -121,18 +117,11 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, |
121 | 117 | throw new ArgumentOutOfRangeException(nameof(charIndex), |
122 | 118 | SR.ArgumentOutOfRange_Index); |
123 | 119 |
|
124 | | - |
125 | | - // Avoid empty input fixed problem |
126 | | - if (bytes.Length == 0) |
127 | | - bytes = new byte[1]; |
128 | | - |
129 | 120 | int charCount = chars.Length - charIndex; |
130 | | - if (chars.Length == 0) |
131 | | - chars = new char[1]; |
132 | 121 |
|
133 | 122 | // Just call pointer version |
134 | | - fixed (byte* pBytes = &bytes[0]) |
135 | | - fixed (char* pChars = &chars[0]) |
| 123 | + fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes)) |
| 124 | + fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars)) |
136 | 125 | // Remember that charCount is # to decode, not size of array |
137 | 126 | return GetChars(pBytes + byteIndex, byteCount, |
138 | 127 | pChars + charIndex, charCount, flush); |
@@ -185,17 +174,10 @@ public override unsafe void Convert(byte[] bytes, int byteIndex, int byteCount, |
185 | 174 | throw new ArgumentOutOfRangeException(nameof(chars), |
186 | 175 | SR.ArgumentOutOfRange_IndexCountBuffer); |
187 | 176 |
|
188 | | - |
189 | | - // Avoid empty input problem |
190 | | - if (bytes.Length == 0) |
191 | | - bytes = new byte[1]; |
192 | | - if (chars.Length == 0) |
193 | | - chars = new char[1]; |
194 | | - |
195 | 177 | // Just call the pointer version (public overrides can't do this) |
196 | | - fixed (byte* pBytes = &bytes[0]) |
| 178 | + fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes)) |
197 | 179 | { |
198 | | - fixed (char* pChars = &chars[0]) |
| 180 | + fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars)) |
199 | 181 | { |
200 | 182 | Convert(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, flush, |
201 | 183 | out bytesUsed, out charsUsed, out completed); |
|
0 commit comments