Skip to content

Commit e45a913

Browse files
authored
Optimize: use SequnceCompareTo to compare bytes (#3949)
1 parent 6ee41ed commit e45a913

File tree

3 files changed

+9
-66
lines changed

3 files changed

+9
-66
lines changed

src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Helper.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.Find.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@ private ReadOnlySpan<byte> Seek(ref Node node, ReadOnlySpan<byte> path, out Node
134134
for (int i = 0; i < Node.BranchChildCount - 1; i++)
135135
{
136136
if (from[offset] < i)
137+
{
137138
foreach (var item in Travers(node.Children[i], [.. path, .. new byte[] { (byte)i }], from, from.Length))
138139
yield return item;
140+
}
139141
else if (i == from[offset])
142+
{
140143
foreach (var item in Travers(node.Children[i], [.. path, .. new byte[] { (byte)i }], from, offset + 1))
141144
yield return item;
145+
}
142146
}
143147
}
144148
else
@@ -156,11 +160,15 @@ private ReadOnlySpan<byte> Seek(ref Node node, ReadOnlySpan<byte> path, out Node
156160
case NodeType.ExtensionNode:
157161
{
158162
if (offset < from.Length && from.AsSpan()[offset..].StartsWith(node.Key.Span))
163+
{
159164
foreach (var item in Travers(node.Next, [.. path, .. node.Key.Span], from, offset + node.Key.Length))
160165
yield return item;
161-
else if (from.Length <= offset || 0 < node.Key.Span.CompareTo(from.AsSpan(offset)))
166+
}
167+
else if (from.Length <= offset || 0 < node.Key.Span.SequenceCompareTo(from.AsSpan(offset)))
168+
{
162169
foreach (var item in Travers(node.Next, [.. path, .. node.Key.Span], from, from.Length))
163170
yield return item;
171+
}
164172
break;
165173
}
166174
}

tests/Neo.Cryptography.MPTTrie.Tests/Cryptography/MPTTrie/UT_Helper.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)