mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
mpt: refactor lcp
to be possible to use range
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 <carpawell@nspcc.ru>
This commit is contained in:
parent
32f91dd726
commit
f8549a4fb8
1 changed files with 3 additions and 7 deletions
|
@ -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` loop 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 {
|
||||
|
|
Loading…
Reference in a new issue