Skip to content
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/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.Put.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
// modifications are permitted.

using System;
using System.Runtime.CompilerServices;

namespace Neo.Cryptography.MPTTrie
{
partial class Trie
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ReadOnlySpan<byte> CommonPrefix(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
{
var minLen = a.Length <= b.Length ? a.Length : b.Length;
var i = 0;
if (a.Length != 0 && b.Length != 0)
{
for (i = 0; i < minLen; i++)
{
if (a[i] != b[i]) break;
}
}
return a[..i];
int offset = a.CommonPrefixLength(b);
return a[..offset];
}

public void Put(byte[] key, byte[] value)
Expand Down