2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- #nullable enable
6
5
// The worker functions in this file was optimized for performance. If you make changes
7
6
// you should use care to consider all of the interesting cases.
8
7
11
10
// The fast loops attempts to blaze through as fast as possible with optimistic range checks,
12
11
// processing multiple characters at a time, and falling back to the slow loop for all special cases.
13
12
13
+ #nullable enable
14
14
using System ;
15
15
using System . Buffers ;
16
16
using System . Diagnostics ;
@@ -139,7 +139,7 @@ public override unsafe int GetByteCount(char[] chars, int index, int count)
139
139
ThrowHelper . ThrowArgumentOutOfRangeException ( ( index < 0 ) ? ExceptionArgument . index : ExceptionArgument . count , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
140
140
}
141
141
142
- if ( chars . Length - index < count )
142
+ if ( chars ! . Length - index < count ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
143
143
{
144
144
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . chars , ExceptionResource . ArgumentOutOfRange_IndexCountBuffer ) ;
145
145
}
@@ -166,7 +166,7 @@ public override unsafe int GetByteCount(string chars)
166
166
167
167
fixed ( char * pChars = chars )
168
168
{
169
- return GetByteCountCommon ( pChars , chars . Length ) ;
169
+ return GetByteCountCommon ( pChars , chars ! . Length ) ; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
170
170
}
171
171
}
172
172
@@ -233,7 +233,7 @@ private unsafe int GetByteCountCommon(char* pChars, int charCount)
233
233
}
234
234
235
235
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ] // called directly by GetCharCountCommon
236
- private protected sealed override unsafe int GetByteCountFast ( char * pChars , int charsLength , EncoderFallback fallback , out int charsConsumed )
236
+ private protected sealed override unsafe int GetByteCountFast ( char * pChars , int charsLength , EncoderFallback ? fallback , out int charsConsumed )
237
237
{
238
238
// The number of UTF-8 code units may exceed the number of UTF-16 code units,
239
239
// so we'll need to check for overflow before casting to Int32.
@@ -276,12 +276,12 @@ public override unsafe int GetBytes(string s, int charIndex, int charCount,
276
276
resource : ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
277
277
}
278
278
279
- if ( s . Length - charIndex < charCount )
279
+ if ( s ! . Length - charIndex < charCount ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
280
280
{
281
281
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . s , ExceptionResource . ArgumentOutOfRange_IndexCount ) ;
282
282
}
283
283
284
- if ( ( uint ) byteIndex > bytes . Length )
284
+ if ( ( uint ) byteIndex > bytes ! . Length ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
285
285
{
286
286
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . byteIndex , ExceptionResource . ArgumentOutOfRange_Index ) ;
287
287
}
@@ -326,12 +326,12 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
326
326
resource : ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
327
327
}
328
328
329
- if ( chars . Length - charIndex < charCount )
329
+ if ( chars ! . Length - charIndex < charCount ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
330
330
{
331
331
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . chars , ExceptionResource . ArgumentOutOfRange_IndexCount ) ;
332
332
}
333
333
334
- if ( ( uint ) byteIndex > bytes . Length )
334
+ if ( ( uint ) byteIndex > bytes ! . Length ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
335
335
{
336
336
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . byteIndex , ExceptionResource . ArgumentOutOfRange_Index ) ;
337
337
}
@@ -444,7 +444,7 @@ public override unsafe int GetCharCount(byte[] bytes, int index, int count)
444
444
ThrowHelper . ThrowArgumentOutOfRangeException ( ( index < 0 ) ? ExceptionArgument . index : ExceptionArgument . count , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
445
445
}
446
446
447
- if ( bytes . Length - index < count )
447
+ if ( bytes ! . Length - index < count ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
448
448
{
449
449
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . bytes , ExceptionResource . ArgumentOutOfRange_IndexCountBuffer ) ;
450
450
}
@@ -511,12 +511,12 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
511
511
resource : ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
512
512
}
513
513
514
- if ( bytes . Length - byteIndex < byteCount )
514
+ if ( bytes ! . Length - byteIndex < byteCount ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
515
515
{
516
516
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . bytes , ExceptionResource . ArgumentOutOfRange_IndexCountBuffer ) ;
517
517
}
518
518
519
- if ( ( uint ) charIndex > ( uint ) chars . Length )
519
+ if ( ( uint ) charIndex > ( uint ) chars ! . Length ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
520
520
{
521
521
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . charIndex , ExceptionResource . ArgumentOutOfRange_Index ) ;
522
522
}
@@ -614,7 +614,7 @@ private protected sealed override unsafe int GetCharsFast(byte* pBytes, int byte
614
614
return ( int ) ( pOutputBufferRemaining - pChars ) ;
615
615
}
616
616
617
- private protected sealed override unsafe int GetCharsWithFallback ( ReadOnlySpan < byte > bytes , int originalBytesLength , Span < char > chars , int originalCharsLength , DecoderNLS decoder )
617
+ private protected sealed override unsafe int GetCharsWithFallback ( ReadOnlySpan < byte > bytes , int originalBytesLength , Span < char > chars , int originalCharsLength , DecoderNLS ? decoder )
618
618
{
619
619
// We special-case DecoderReplacementFallback if it's telling us to write a single U+FFFD char,
620
620
// since we believe this to be relatively common and we can handle it more efficiently than
@@ -673,7 +673,7 @@ public override unsafe string GetString(byte[] bytes, int index, int count)
673
673
resource : ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
674
674
}
675
675
676
- if ( bytes . Length - index < count )
676
+ if ( bytes ! . Length - index < count ) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
677
677
{
678
678
ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . bytes , ExceptionResource . ArgumentOutOfRange_IndexCountBuffer ) ;
679
679
}
@@ -723,7 +723,7 @@ private unsafe int GetCharCountCommon(byte* pBytes, int byteCount)
723
723
}
724
724
725
725
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ] // called directly by GetCharCountCommon
726
- private protected sealed override unsafe int GetCharCountFast ( byte * pBytes , int bytesLength , DecoderFallback fallback , out int bytesConsumed )
726
+ private protected sealed override unsafe int GetCharCountFast ( byte * pBytes , int bytesLength , DecoderFallback ? fallback , out int bytesConsumed )
727
727
{
728
728
// The number of UTF-16 code units will never exceed the number of UTF-8 code units,
729
729
// so the addition at the end of this method will not overflow.
0 commit comments