@@ -379,22 +379,22 @@ public override int Read(byte[] buffer, int offset, int count)
379
379
return ReadCore ( new Span < byte > ( buffer , offset , count ) ) ;
380
380
}
381
381
382
- public override int Read ( Span < byte > destination )
382
+ public override int Read ( Span < byte > buffer )
383
383
{
384
384
if ( GetType ( ) == typeof ( UnmanagedMemoryStream ) )
385
385
{
386
- return ReadCore ( destination ) ;
386
+ return ReadCore ( buffer ) ;
387
387
}
388
388
else
389
389
{
390
390
// UnmanagedMemoryStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior
391
391
// to this Read(Span<byte>) overload being introduced. In that case, this Read(Span<byte>) overload
392
392
// should use the behavior of Read(byte[],int,int) overload.
393
- return base . Read ( destination ) ;
393
+ return base . Read ( buffer ) ;
394
394
}
395
395
}
396
396
397
- internal int ReadCore ( Span < byte > destination )
397
+ internal int ReadCore ( Span < byte > buffer )
398
398
{
399
399
EnsureNotClosed ( ) ;
400
400
EnsureReadable ( ) ;
@@ -403,7 +403,7 @@ internal int ReadCore(Span<byte> destination)
403
403
// changes our position after we decide we can read some bytes.
404
404
long pos = Interlocked . Read ( ref _position ) ;
405
405
long len = Interlocked . Read ( ref _length ) ;
406
- long n = Math . Min ( len - pos , destination . Length ) ;
406
+ long n = Math . Min ( len - pos , buffer . Length ) ;
407
407
if ( n <= 0 )
408
408
{
409
409
return 0 ;
@@ -418,7 +418,7 @@ internal int ReadCore(Span<byte> destination)
418
418
419
419
unsafe
420
420
{
421
- fixed ( byte * pBuffer = & MemoryMarshal . GetReference ( destination ) )
421
+ fixed ( byte * pBuffer = & MemoryMarshal . GetReference ( buffer ) )
422
422
{
423
423
if ( _buffer != null )
424
424
{
@@ -486,9 +486,9 @@ public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count,
486
486
/// <summary>
487
487
/// Reads bytes from stream and puts them into the buffer
488
488
/// </summary>
489
- /// <param name="destination ">Buffer to read the bytes to.</param>
489
+ /// <param name="buffer ">Buffer to read the bytes to.</param>
490
490
/// <param name="cancellationToken">Token that can be used to cancel this operation.</param>
491
- public override ValueTask < int > ReadAsync ( Memory < byte > destination , CancellationToken cancellationToken = default ( CancellationToken ) )
491
+ public override ValueTask < int > ReadAsync ( Memory < byte > buffer , CancellationToken cancellationToken = default ( CancellationToken ) )
492
492
{
493
493
if ( cancellationToken . IsCancellationRequested )
494
494
{
@@ -510,9 +510,9 @@ public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count,
510
510
// something other than an array and this is an UnmanagedMemoryStream-derived type that doesn't override Read(Span<byte>) will
511
511
// it then fall back to doing the ArrayPool/copy behavior.
512
512
return new ValueTask < int > (
513
- MemoryMarshal . TryGetArray ( destination , out ArraySegment < byte > destinationArray ) ?
513
+ MemoryMarshal . TryGetArray ( buffer , out ArraySegment < byte > destinationArray ) ?
514
514
Read ( destinationArray . Array , destinationArray . Offset , destinationArray . Count ) :
515
- Read ( destination . Span ) ) ;
515
+ Read ( buffer . Span ) ) ;
516
516
}
517
517
catch ( Exception ex )
518
518
{
@@ -659,29 +659,29 @@ public override void Write(byte[] buffer, int offset, int count)
659
659
WriteCore ( new Span < byte > ( buffer , offset , count ) ) ;
660
660
}
661
661
662
- public override void Write ( ReadOnlySpan < byte > source )
662
+ public override void Write ( ReadOnlySpan < byte > buffer )
663
663
{
664
664
if ( GetType ( ) == typeof ( UnmanagedMemoryStream ) )
665
665
{
666
- WriteCore ( source ) ;
666
+ WriteCore ( buffer ) ;
667
667
}
668
668
else
669
669
{
670
670
// UnmanagedMemoryStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
671
671
// to this Write(Span<byte>) overload being introduced. In that case, this Write(Span<byte>) overload
672
672
// should use the behavior of Write(byte[],int,int) overload.
673
- base . Write ( source ) ;
673
+ base . Write ( buffer ) ;
674
674
}
675
675
}
676
676
677
- internal unsafe void WriteCore ( ReadOnlySpan < byte > source )
677
+ internal unsafe void WriteCore ( ReadOnlySpan < byte > buffer )
678
678
{
679
679
EnsureNotClosed ( ) ;
680
680
EnsureWriteable ( ) ;
681
681
682
682
long pos = Interlocked . Read ( ref _position ) ; // Use a local to avoid a race condition
683
683
long len = Interlocked . Read ( ref _length ) ;
684
- long n = pos + source . Length ;
684
+ long n = pos + buffer . Length ;
685
685
// Check for overflow
686
686
if ( n < 0 )
687
687
{
@@ -709,12 +709,12 @@ internal unsafe void WriteCore(ReadOnlySpan<byte> source)
709
709
}
710
710
}
711
711
712
- fixed ( byte * pBuffer = & MemoryMarshal . GetReference ( source ) )
712
+ fixed ( byte * pBuffer = & MemoryMarshal . GetReference ( buffer ) )
713
713
{
714
714
if ( _buffer != null )
715
715
{
716
716
long bytesLeft = _capacity - pos ;
717
- if ( bytesLeft < source . Length )
717
+ if ( bytesLeft < buffer . Length )
718
718
{
719
719
throw new ArgumentException ( SR . Arg_BufferTooSmall ) ;
720
720
}
@@ -724,7 +724,7 @@ internal unsafe void WriteCore(ReadOnlySpan<byte> source)
724
724
try
725
725
{
726
726
_buffer . AcquirePointer ( ref pointer ) ;
727
- Buffer . Memcpy ( pointer + pos + _offset , pBuffer , source . Length ) ;
727
+ Buffer . Memcpy ( pointer + pos + _offset , pBuffer , buffer . Length ) ;
728
728
}
729
729
finally
730
730
{
@@ -736,7 +736,7 @@ internal unsafe void WriteCore(ReadOnlySpan<byte> source)
736
736
}
737
737
else
738
738
{
739
- Buffer . Memcpy ( _mem + pos , pBuffer , source . Length ) ;
739
+ Buffer . Memcpy ( _mem + pos , pBuffer , buffer . Length ) ;
740
740
}
741
741
}
742
742
@@ -783,7 +783,7 @@ public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, Cancel
783
783
/// </summary>
784
784
/// <param name="buffer">Buffer that will be written.</param>
785
785
/// <param name="cancellationToken">Token that can be used to cancel the operation.</param>
786
- public override ValueTask WriteAsync ( ReadOnlyMemory < byte > source , CancellationToken cancellationToken = default ( CancellationToken ) )
786
+ public override ValueTask WriteAsync ( ReadOnlyMemory < byte > buffer , CancellationToken cancellationToken = default ( CancellationToken ) )
787
787
{
788
788
if ( cancellationToken . IsCancellationRequested )
789
789
{
@@ -794,13 +794,13 @@ public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, Cancel
794
794
{
795
795
// See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>).
796
796
// Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency.
797
- if ( MemoryMarshal . TryGetArray ( source , out ArraySegment < byte > sourceArray ) )
797
+ if ( MemoryMarshal . TryGetArray ( buffer , out ArraySegment < byte > sourceArray ) )
798
798
{
799
799
Write ( sourceArray . Array , sourceArray . Offset , sourceArray . Count ) ;
800
800
}
801
801
else
802
802
{
803
- Write ( source . Span ) ;
803
+ Write ( buffer . Span ) ;
804
804
}
805
805
return default ;
806
806
}
0 commit comments