Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Aug 18, 2024
1 parent 89958c4 commit 81e0fde
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Core/Crypto/KeccakCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public static ValueHash256 Compute(ReadOnlySpan<byte> input)

// Try lock and memoize
int length = Volatile.Read(ref e.LockAndLength);
// Negative value means that the entry is locked, set to int.MinValue to avoid confusion empty entry.
// Negative value means that the entry is locked, set to int.MinValue to avoid confusion empty entry,
// since we are overwriting it anyway e.g. -0 would not be a reliable locked state.
if (length >= 0 && Interlocked.CompareExchange(ref e.LockAndLength, int.MinValue, length) == length)
{
e.Hash = fast;
Expand Down Expand Up @@ -135,13 +136,12 @@ private struct Entry
private const int ValueStart = Size - ValueHash256.MemorySize;
public const int MaxPayloadLength = ValueStart - PayloadStart;

/// <summary>
/// Length is always positive so we can use a negative length to indicate that it is locked.
/// </summary>
[FieldOffset(0)]
public int LockAndLength;

/// <summary>
/// The mix of hash and length allows for a fast comparison and a single volatile read.
/// The length is encoded as the low part, while the hash as the high part of uint.
/// </summary>
[FieldOffset(4)]
public int Hash;

Expand Down

0 comments on commit 81e0fde

Please sign in to comment.