Skip to content

Commit

Permalink
Make CappedArray readonly (#6434)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Dec 29, 2023
1 parent 075365a commit f601ede
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;

namespace Nethermind.Core.Buffers;

Expand All @@ -13,10 +11,10 @@ namespace Nethermind.Core.Buffers;
/// underlying array can be null and this struct is meant to be non nullable, checking the `IsNull` property to check
/// if it represent null.
/// </summary>
public struct CappedArray<T>
public readonly struct CappedArray<T>
{
private readonly T[]? _array = null;
private int _length = 0;
private readonly int _length = 0;

public CappedArray(T[]? array, int length)
{
Expand Down Expand Up @@ -44,11 +42,7 @@ public static implicit operator CappedArray<T>(T[]? array)
return new CappedArray<T>(array);
}

public int Length
{
readonly get => _length;
set => _length = value;
}
public readonly int Length => _length;

public readonly T[]? Array => _array;
public readonly bool IsUncapped => _length == _array?.Length;
Expand All @@ -60,7 +54,7 @@ public readonly Span<T> AsSpan()
return _array.AsSpan()[..Length];
}

public T[]? ToArray()
public readonly T[]? ToArray()
{
if (_array is null) return null;
if (_length == _array?.Length) return _array;
Expand Down

0 comments on commit f601ede

Please sign in to comment.