Skip to content

Commit

Permalink
mpt: 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. Also, a
correct code is always better than a correct code with `nolint`.

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

var i int
//nolint:intrange // if slices are the same (or one is a prefix for another
// one), `range` loops does not assign the latest index to the `i` var, and
// the func loses the latest element
for i = 0; i < len(b); i++ {
for i := range b {
if a[i] != b[i] {
break
return b[:i]
}
}

return a[:i]
return b
}

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

0 comments on commit 320d33b

Please sign in to comment.