diff options
Diffstat (limited to 'ethtrie/slice.go')
-rw-r--r-- | ethtrie/slice.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ethtrie/slice.go b/ethtrie/slice.go index b9d5d1285..cf4e8df7a 100644 --- a/ethtrie/slice.go +++ b/ethtrie/slice.go @@ -1,6 +1,6 @@ package ethtrie -import () +import "math" // Helper function for comparing slices func CompareIntSlice(a, b []int) bool { @@ -17,9 +17,13 @@ func CompareIntSlice(a, b []int) bool { // Returns the amount of nibbles that match each other from 0 ... func MatchingNibbleLength(a, b []int) int { - i := 0 - for CompareIntSlice(a[:i+1], b[:i+1]) && i < len(b) { - i += 1 + var i, length = 0, int(math.Min(float64(len(a)), float64(len(b)))) + + for i < length { + if a[i] != b[i] { + break + } + i++ } return i |