-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce allocations in StorageRangesMessageSerializer (#6534)
- Loading branch information
Showing
2 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 18 additions & 6 deletions
24
src/Nethermind/Nethermind.State/Snap/PathWithStorageSlot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Numerics; | ||
using Nethermind.Core.Crypto; | ||
|
||
namespace Nethermind.State.Snap | ||
{ | ||
public class PathWithStorageSlot | ||
public readonly struct PathWithStorageSlot(ValueHash256 keyHash, byte[] slotRlpValue) | ||
: IEquatable<PathWithStorageSlot>, IEqualityOperators<PathWithStorageSlot, PathWithStorageSlot, bool> | ||
{ | ||
public PathWithStorageSlot(ValueHash256 keyHash, byte[] slotRlpValue) | ||
public ValueHash256 Path { get; } = keyHash; | ||
public byte[] SlotRlpValue { get; } = slotRlpValue; | ||
|
||
public bool Equals(in PathWithStorageSlot other) | ||
{ | ||
Path = keyHash; | ||
SlotRlpValue = slotRlpValue; | ||
return Path == other.Path && SlotRlpValue.AsSpan().SequenceEqual(other.SlotRlpValue); | ||
} | ||
|
||
public ValueHash256 Path { get; set; } | ||
public byte[] SlotRlpValue { get; set; } | ||
public bool Equals(PathWithStorageSlot other) => Equals(in other); | ||
|
||
public static bool operator ==(PathWithStorageSlot left, PathWithStorageSlot right) => left.Equals(in right); | ||
|
||
public static bool operator !=(PathWithStorageSlot left, PathWithStorageSlot right) => !left.Equals(in right); | ||
|
||
public override bool Equals(object obj) => obj is PathWithStorageSlot pws && Equals(in pws); | ||
|
||
public override int GetHashCode() => throw new NotImplementedException(); | ||
} | ||
} |