diff options
author | Anirudh Agnihotry <anirudhagnihotry098@gmail.com> | 2018-03-23 15:43:47 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-03-23 17:21:48 +0300 |
commit | 85b8a261218078071e6ab147e37521b92948ea79 (patch) | |
tree | 5c214ac6e8079e6ac6d6d1409002080729f467c8 /src | |
parent | ed61762299551768ea1bddbb97e36417f83db921 (diff) |
Rename new Stream.Read/Write{Async} Span/Memory source/Destination arguments to buffer (#17141)
* changed to buffer
* More Common changes
* fixed
* another fix
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src')
5 files changed, 58 insertions, 58 deletions
diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.cs index 717b73ff1..a6ad63c6e 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.cs @@ -304,7 +304,7 @@ namespace System.IO ReadSpan(new Span<byte>(array, offset, count)); } - public override int Read(Span<byte> destination) + public override int Read(Span<byte> buffer) { if (GetType() == typeof(FileStream) && !_useAsyncIO) { @@ -312,7 +312,7 @@ namespace System.IO { throw Error.GetFileNotOpen(); } - return ReadSpan(destination); + return ReadSpan(buffer); } else { @@ -322,7 +322,7 @@ namespace System.IO // of Read(byte[],int,int) overload. Or if the stream is in async mode, we can't call the // synchronous ReadSpan, so we similarly call the base Read, which will turn delegate to // Read(byte[],int,int), which will do the right thing if we're in async mode. - return base.Read(destination); + return base.Read(buffer); } } @@ -355,14 +355,14 @@ namespace System.IO return ReadAsyncTask(buffer, offset, count, cancellationToken); } - public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (!_useAsyncIO || GetType() != typeof(FileStream)) { // If we're not using async I/O, delegate to the base, which will queue a call to Read. // Or if this isn't a concrete FileStream, a derived type may have overridden ReadAsync(byte[],...), // which was introduced first, so delegate to the base which will delegate to that. - return base.ReadAsync(destination, cancellationToken); + return base.ReadAsync(buffer, cancellationToken); } if (cancellationToken.IsCancellationRequested) @@ -375,7 +375,7 @@ namespace System.IO throw Error.GetFileNotOpen(); } - Task<int> t = ReadAsyncInternal(destination, cancellationToken, out int synchronousResult); + Task<int> t = ReadAsyncInternal(buffer, cancellationToken, out int synchronousResult); return t != null ? new ValueTask<int>(t) : new ValueTask<int>(synchronousResult); @@ -412,7 +412,7 @@ namespace System.IO } } - public override void Write(ReadOnlySpan<byte> destination) + public override void Write(ReadOnlySpan<byte> buffer) { if (GetType() == typeof(FileStream) && !_useAsyncIO) { @@ -420,7 +420,7 @@ namespace System.IO { throw Error.GetFileNotOpen(); } - WriteSpan(destination); + WriteSpan(buffer); } else { @@ -430,7 +430,7 @@ namespace System.IO // of Write(byte[],int,int) overload. Or if the stream is in async mode, we can't call the // synchronous WriteSpan, so we similarly call the base Write, which will turn delegate to // Write(byte[],int,int), which will do the right thing if we're in async mode. - base.Write(destination); + base.Write(buffer); } } @@ -461,14 +461,14 @@ namespace System.IO return WriteAsyncInternal(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken).AsTask(); } - public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (!_useAsyncIO || GetType() != typeof(FileStream)) { // If we're not using async I/O, delegate to the base, which will queue a call to Write. // Or if this isn't a concrete FileStream, a derived type may have overridden WriteAsync(byte[],...), // which was introduced first, so delegate to the base which will delegate to that. - return base.WriteAsync(source, cancellationToken); + return base.WriteAsync(buffer, cancellationToken); } if (cancellationToken.IsCancellationRequested) @@ -481,7 +481,7 @@ namespace System.IO throw Error.GetFileNotOpen(); } - return WriteAsyncInternal(source, cancellationToken); + return WriteAsyncInternal(buffer, cancellationToken); } /// <summary> diff --git a/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs b/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs index ffe7f6093..fb319de7c 100644 --- a/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs @@ -367,19 +367,19 @@ namespace System.IO return n; } - public override int Read(Span<byte> destination) + public override int Read(Span<byte> buffer) { if (GetType() != typeof(MemoryStream)) { // MemoryStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior // to this Read(Span<byte>) overload being introduced. In that case, this Read(Span<byte>) overload // should use the behavior of Read(byte[],int,int) overload. - return base.Read(destination); + return base.Read(buffer); } EnsureNotClosed(); - int n = Math.Min(_length - _position, destination.Length); + int n = Math.Min(_length - _position, buffer.Length); if (n <= 0) return 0; @@ -387,7 +387,7 @@ namespace System.IO // Read(byte[], int, int) has an n <= 8 optimization, presumably based // on benchmarking. Determine if/where such a cut-off is here and add // an equivalent optimization if necessary. - new Span<byte>(_buffer, _position, n).CopyTo(destination); + new Span<byte>(_buffer, _position, n).CopyTo(buffer); _position += n; return n; @@ -426,7 +426,7 @@ namespace System.IO } } - public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) { @@ -448,9 +448,9 @@ namespace System.IO // something other than an array and this is a MemoryStream-derived type that doesn't override Read(Span<byte>) will // it then fall back to doing the ArrayPool/copy behavior. return new ValueTask<int>( - MemoryMarshal.TryGetArray(destination, out ArraySegment<byte> destinationArray) ? + MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> destinationArray) ? Read(destinationArray.Array, destinationArray.Offset, destinationArray.Count) : - Read(destination.Span)); + Read(buffer.Span)); } catch (OperationCanceledException oce) { @@ -681,14 +681,14 @@ namespace System.IO _position = i; } - public override void Write(ReadOnlySpan<byte> source) + public override void Write(ReadOnlySpan<byte> buffer) { if (GetType() != typeof(MemoryStream)) { // MemoryStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior // to this Write(Span<byte>) overload being introduced. In that case, this Write(Span<byte>) overload // should use the behavior of Write(byte[],int,int) overload. - base.Write(source); + base.Write(buffer); return; } @@ -696,7 +696,7 @@ namespace System.IO EnsureWriteable(); // Check for overflow - int i = _position + source.Length; + int i = _position + buffer.Length; if (i < 0) throw new IOException(SR.IO_StreamTooLong); @@ -718,7 +718,7 @@ namespace System.IO _length = i; } - source.CopyTo(new Span<byte>(_buffer, _position, source.Length)); + buffer.CopyTo(new Span<byte>(_buffer, _position, buffer.Length)); _position = i; } @@ -752,7 +752,7 @@ namespace System.IO } } - public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) { @@ -763,13 +763,13 @@ namespace System.IO { // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>). // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency. - if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray)) + if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> sourceArray)) { Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count); } else { - Write(source.Span); + Write(buffer.Span); } return default; } diff --git a/src/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs b/src/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs index dfcc05d06..94331a2ef 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs @@ -38,9 +38,9 @@ namespace System.IO Initialize(ptr, len, len, FileAccess.Read); } - public override int Read(Span<byte> destination) => ReadCore(destination); + public override int Read(Span<byte> buffer) => ReadCore(buffer); - public override void Write(ReadOnlySpan<byte> source) => WriteCore(source); + public override void Write(ReadOnlySpan<byte> buffer) => WriteCore(buffer); ~PinnedBufferMemoryStream() { diff --git a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs index d1a13156a..2bcb16f24 100644 --- a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs @@ -379,22 +379,22 @@ namespace System.IO return ReadCore(new Span<byte>(buffer, offset, count)); } - public override int Read(Span<byte> destination) + public override int Read(Span<byte> buffer) { if (GetType() == typeof(UnmanagedMemoryStream)) { - return ReadCore(destination); + return ReadCore(buffer); } else { // UnmanagedMemoryStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior // to this Read(Span<byte>) overload being introduced. In that case, this Read(Span<byte>) overload // should use the behavior of Read(byte[],int,int) overload. - return base.Read(destination); + return base.Read(buffer); } } - internal int ReadCore(Span<byte> destination) + internal int ReadCore(Span<byte> buffer) { EnsureNotClosed(); EnsureReadable(); @@ -403,7 +403,7 @@ namespace System.IO // changes our position after we decide we can read some bytes. long pos = Interlocked.Read(ref _position); long len = Interlocked.Read(ref _length); - long n = Math.Min(len - pos, destination.Length); + long n = Math.Min(len - pos, buffer.Length); if (n <= 0) { return 0; @@ -418,7 +418,7 @@ namespace System.IO unsafe { - fixed (byte* pBuffer = &MemoryMarshal.GetReference(destination)) + fixed (byte* pBuffer = &MemoryMarshal.GetReference(buffer)) { if (_buffer != null) { @@ -486,9 +486,9 @@ namespace System.IO /// <summary> /// Reads bytes from stream and puts them into the buffer /// </summary> - /// <param name="destination">Buffer to read the bytes to.</param> + /// <param name="buffer">Buffer to read the bytes to.</param> /// <param name="cancellationToken">Token that can be used to cancel this operation.</param> - public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) { @@ -510,9 +510,9 @@ namespace System.IO // something other than an array and this is an UnmanagedMemoryStream-derived type that doesn't override Read(Span<byte>) will // it then fall back to doing the ArrayPool/copy behavior. return new ValueTask<int>( - MemoryMarshal.TryGetArray(destination, out ArraySegment<byte> destinationArray) ? + MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> destinationArray) ? Read(destinationArray.Array, destinationArray.Offset, destinationArray.Count) : - Read(destination.Span)); + Read(buffer.Span)); } catch (Exception ex) { @@ -659,29 +659,29 @@ namespace System.IO WriteCore(new Span<byte>(buffer, offset, count)); } - public override void Write(ReadOnlySpan<byte> source) + public override void Write(ReadOnlySpan<byte> buffer) { if (GetType() == typeof(UnmanagedMemoryStream)) { - WriteCore(source); + WriteCore(buffer); } else { // UnmanagedMemoryStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior // to this Write(Span<byte>) overload being introduced. In that case, this Write(Span<byte>) overload // should use the behavior of Write(byte[],int,int) overload. - base.Write(source); + base.Write(buffer); } } - internal unsafe void WriteCore(ReadOnlySpan<byte> source) + internal unsafe void WriteCore(ReadOnlySpan<byte> buffer) { EnsureNotClosed(); EnsureWriteable(); long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition long len = Interlocked.Read(ref _length); - long n = pos + source.Length; + long n = pos + buffer.Length; // Check for overflow if (n < 0) { @@ -709,12 +709,12 @@ namespace System.IO } } - fixed (byte* pBuffer = &MemoryMarshal.GetReference(source)) + fixed (byte* pBuffer = &MemoryMarshal.GetReference(buffer)) { if (_buffer != null) { long bytesLeft = _capacity - pos; - if (bytesLeft < source.Length) + if (bytesLeft < buffer.Length) { throw new ArgumentException(SR.Arg_BufferTooSmall); } @@ -724,7 +724,7 @@ namespace System.IO try { _buffer.AcquirePointer(ref pointer); - Buffer.Memcpy(pointer + pos + _offset, pBuffer, source.Length); + Buffer.Memcpy(pointer + pos + _offset, pBuffer, buffer.Length); } finally { @@ -736,7 +736,7 @@ namespace System.IO } else { - Buffer.Memcpy(_mem + pos, pBuffer, source.Length); + Buffer.Memcpy(_mem + pos, pBuffer, buffer.Length); } } @@ -783,7 +783,7 @@ namespace System.IO /// </summary> /// <param name="buffer">Buffer that will be written.</param> /// <param name="cancellationToken">Token that can be used to cancel the operation.</param> - public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) { @@ -794,13 +794,13 @@ namespace System.IO { // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>). // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency. - if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray)) + if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> sourceArray)) { Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count); } else { - Write(source.Span); + Write(buffer.Span); } return default; } diff --git a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs index f34c3c413..65a33961d 100644 --- a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs +++ b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs @@ -112,9 +112,9 @@ namespace System.IO return _unmanagedStream.Read(buffer, offset, count); } - public override int Read(Span<byte> destination) + public override int Read(Span<byte> buffer) { - return _unmanagedStream.Read(destination); + return _unmanagedStream.Read(buffer); } public override int ReadByte() @@ -139,9 +139,9 @@ namespace System.IO _unmanagedStream.Write(buffer, offset, count); } - public override void Write(ReadOnlySpan<byte> source) + public override void Write(ReadOnlySpan<byte> buffer) { - _unmanagedStream.Write(source); + _unmanagedStream.Write(buffer); } public override void WriteByte(byte value) @@ -206,9 +206,9 @@ namespace System.IO return _unmanagedStream.ReadAsync(buffer, offset, count, cancellationToken); } - public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { - return _unmanagedStream.ReadAsync(destination, cancellationToken); + return _unmanagedStream.ReadAsync(buffer, cancellationToken); } @@ -217,9 +217,9 @@ namespace System.IO return _unmanagedStream.WriteAsync(buffer, offset, count, cancellationToken); } - public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken)) { - return _unmanagedStream.WriteAsync(source, cancellationToken); + return _unmanagedStream.WriteAsync(buffer, cancellationToken); } } // class UnmanagedMemoryStreamWrapper } // namespace |