Skip to content

Commit

Permalink
Remove one ToArray
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej committed Nov 27, 2023
1 parent ef6c4e5 commit edd15d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/Nethermind/Nethermind.Blockchain/BlockTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,10 +1606,7 @@ public void ForkChoiceUpdated(Hash256? finalizedBlockHash, Hash256? safeBlockHas
_metadataDb.Set(MetadataDbKeys.SafeBlockHash, Rlp.Encode(SafeHash!).Bytes);
}
}

public Block[] GetInvalidBlocks()
{
return _invalidBlocks.ToArray().Select(x => x.Value).ToArray();
}

public Block[] GetInvalidBlocks() => _invalidBlocks.GetValues();
}
}
13 changes: 13 additions & 0 deletions src/Nethermind/Nethermind.Core/Caching/LruCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ public KeyValuePair<TKey, TValue>[] ToArray()
return array;
}

[MethodImpl(MethodImplOptions.Synchronized)]
public TValue[] GetValues()
{
int i = 0;
TValue[] array = new TValue[_cacheMap.Count];
foreach (KeyValuePair<TKey, LinkedListNode<LruCacheItem>> kvp in _cacheMap)
{
array[i++] = kvp.Value.Value.Value;
}

return array;
}

private void Replace(TKey key, TValue value)
{
LinkedListNode<LruCacheItem>? node = _leastRecentlyUsed;
Expand Down

0 comments on commit edd15d9

Please sign in to comment.