From b34acc9e86b186aa7fbe64bb2651f82116433ec7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 7 Jun 2019 08:51:46 -0700 Subject: [PATCH] Removed BufferSegment (#10982) - This was leftover from the old StreamPipeReader impl --- src/Http/Http/src/BufferSegment.cs | 135 ----------------------------- 1 file changed, 135 deletions(-) delete mode 100644 src/Http/Http/src/BufferSegment.cs diff --git a/src/Http/Http/src/BufferSegment.cs b/src/Http/Http/src/BufferSegment.cs deleted file mode 100644 index 3b04a1b1ec..0000000000 --- a/src/Http/Http/src/BufferSegment.cs +++ /dev/null @@ -1,135 +0,0 @@ -// 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. - -using System.Buffers; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace System.IO.Pipelines -{ - internal sealed class BufferSegment : ReadOnlySequenceSegment - { - private object _memoryOwner; - private BufferSegment _next; - private int _end; - - /// - /// 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 - /// Buffer.Length, and must be equal to or less than End. - /// - public int End - { - get => _end; - set - { - Debug.Assert(value <= AvailableMemory.Length); - - _end = value; - Memory = AvailableMemory.Slice(0, _end); - } - } - - /// - /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is - /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous - /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" - /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. - /// - public BufferSegment NextSegment - { - get => _next; - set - { - _next = value; - Next = value; - } - } - - public void SetMemory(object memoryOwner) - { - if (memoryOwner is IMemoryOwner owner) - { - SetMemory(owner); - } - else if (memoryOwner is byte[] array) - { - SetMemory(array); - } - else - { - Debug.Fail("Unexpected memoryOwner"); - } - } - - public void SetMemory(IMemoryOwner memoryOwner) - { - _memoryOwner = memoryOwner; - - SetUnownedMemory(memoryOwner.Memory); - } - - public void SetMemory(byte[] arrayPoolBuffer) - { - _memoryOwner = arrayPoolBuffer; - - SetUnownedMemory(arrayPoolBuffer); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SetUnownedMemory(Memory memory) - { - AvailableMemory = memory; - RunningIndex = 0; - End = 0; - NextSegment = null; - } - - public void ResetMemory() - { - if (_memoryOwner is IMemoryOwner owner) - { - owner.Dispose(); - } - else if (_memoryOwner is byte[] array) - { - ArrayPool.Shared.Return(array); - } - - _memoryOwner = null; - AvailableMemory = default; - } - - // Exposed for testing - internal object MemoryOwner => _memoryOwner; - - public Memory AvailableMemory { get; private set; } - - public int Length => End; - - /// - /// The amount of writable bytes in this segment. It is the amount of bytes between Length and End - /// - public int WritableBytes - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => AvailableMemory.Length - End; - } - - public void SetNext(BufferSegment segment) - { - Debug.Assert(segment != null); - Debug.Assert(Next == null); - - NextSegment = segment; - - segment = this; - - while (segment.Next != null) - { - segment.NextSegment.RunningIndex = segment.RunningIndex + segment.Length; - segment = segment.NextSegment; - } - } - } -}