Remove .Start from BufferSegment (#6832)

This commit is contained in:
David Fowler 2019-01-28 20:37:25 +00:00 committed by GitHub
parent 447f4bc298
commit 14d8e33a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 23 deletions

View File

@ -13,13 +13,6 @@ namespace System.IO.Pipelines
private BufferSegment _next; private BufferSegment _next;
private int _end; private int _end;
/// <summary>
/// The Start represents the offset into AvailableMemory where the range of "active" bytes begins. At the point when the block is leased
/// the Start is guaranteed to be equal to 0. The value of Start may be assigned anywhere between 0 and
/// AvailableMemory.Length, and must be equal to or less than End.
/// </summary>
public int Start { get; private set; }
/// <summary> /// <summary>
/// The End represents the offset into AvailableMemory where the range of "active" bytes ends. At the point when the block is leased /// The End represents the offset into AvailableMemory where the range of "active" bytes ends. At the point when the block is leased
/// the End is guaranteed to be equal to Start. The value of Start may be assigned anywhere between 0 and /// the End is guaranteed to be equal to Start. The value of Start may be assigned anywhere between 0 and
@ -30,10 +23,10 @@ namespace System.IO.Pipelines
get => _end; get => _end;
set set
{ {
Debug.Assert(value - Start <= AvailableMemory.Length); Debug.Assert(value <= AvailableMemory.Length);
_end = value; _end = value;
Memory = AvailableMemory.Slice(Start, _end - Start); Memory = AvailableMemory.Slice(0, _end);
} }
} }
@ -54,19 +47,13 @@ namespace System.IO.Pipelines
} }
public void SetMemory(IMemoryOwner<byte> memoryOwner) public void SetMemory(IMemoryOwner<byte> memoryOwner)
{
SetMemory(memoryOwner, 0, 0);
}
public void SetMemory(IMemoryOwner<byte> memoryOwner, int start, int end)
{ {
_memoryOwner = memoryOwner; _memoryOwner = memoryOwner;
AvailableMemory = _memoryOwner.Memory; AvailableMemory = _memoryOwner.Memory;
RunningIndex = 0; RunningIndex = 0;
Start = start; End = 0;
End = end;
NextSegment = null; NextSegment = null;
} }
@ -81,7 +68,7 @@ namespace System.IO.Pipelines
public Memory<byte> AvailableMemory { get; private set; } public Memory<byte> AvailableMemory { get; private set; }
public int Length => End - Start; public int Length => End;
/// <summary> /// <summary>
/// The amount of writable bytes in this segment. It is the amount of bytes between Length and End /// The amount of writable bytes in this segment. It is the amount of bytes between Length and End

View File

@ -1,14 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Buffers; using System.Buffers;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -136,7 +132,7 @@ namespace System.IO.Pipelines
{ {
// If we examined everything, we force ReadAsync to actually read from the underlying stream // If we examined everything, we force ReadAsync to actually read from the underlying stream
// instead of returning a ReadResult from TryRead. // instead of returning a ReadResult from TryRead.
_examinedEverything = examinedIndex == _readTail.End - _readTail.Start; _examinedEverything = examinedIndex == _readTail.End;
} }
// Three cases here: // Three cases here:
@ -321,7 +317,7 @@ namespace System.IO.Pipelines
private ReadOnlySequence<byte> GetCurrentReadOnlySequence() private ReadOnlySequence<byte> GetCurrentReadOnlySequence()
{ {
return new ReadOnlySequence<byte>(_readHead, _readIndex, _readTail, _readTail.End - _readTail.Start); return new ReadOnlySequence<byte>(_readHead, _readIndex, _readTail, _readTail.End);
} }
private void AllocateReadTail() private void AllocateReadTail()