Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CappedArray readonly #6434

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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