| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Immutable; |
| | | 5 | | using System.Diagnostics; |
| | | 6 | | |
| | | 7 | | namespace System.Reflection.Internal |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents a memory block backed by an array of bytes. |
| | | 11 | | /// </summary> |
| | | 12 | | internal sealed class ByteArrayMemoryBlock : AbstractMemoryBlock |
| | | 13 | | { |
| | | 14 | | private ByteArrayMemoryProvider _provider; |
| | | 15 | | private readonly int _start; |
| | | 16 | | private readonly int _size; |
| | | 17 | | |
| | 0 | 18 | | internal ByteArrayMemoryBlock(ByteArrayMemoryProvider provider, int start, int size) |
| | 0 | 19 | | { |
| | 0 | 20 | | _provider = provider; |
| | 0 | 21 | | _size = size; |
| | 0 | 22 | | _start = start; |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public override void Dispose() |
| | 0 | 26 | | { |
| | 0 | 27 | | _provider = null!; |
| | 0 | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | public override unsafe byte* Pointer => _provider.Pointer + _start; |
| | 0 | 31 | | public override int Size => _size; |
| | | 32 | | |
| | | 33 | | public override ImmutableArray<byte> GetContentUnchecked(int start, int length) |
| | 0 | 34 | | { |
| | 0 | 35 | | return ImmutableArray.Create(_provider.Array, _start + start, length); |
| | 0 | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |