Skip to content

Commit

Permalink
mtp: refactor lcp to be possible to use range
Browse files Browse the repository at this point in the history
It took some time to understand why changing a regular `for` to a `range`
one leads to behavior changes; let it be more clear and explicit.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Sep 4, 2024
1 parent 1c66a3a commit eeb7c86
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/core/mpt/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ func lcp(a, b []byte) []byte {
return lcp(b, a)
}

var i int
for i = 0; i < len(b); i++ {
for i := range b {
if a[i] != b[i] {
break
return a[:i]
}
}

return a[:i]
return b
}

func lcpMany(kv []keyValue) []byte {
Expand Down

0 comments on commit eeb7c86

Please sign in to comment.