Skip to content

Commit d0a0d91

Browse files
committed
refactor: to use std libary func bytes.CutPrefix
1 parent 9171179 commit d0a0d91

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

store/prefix/store.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ func (pi *prefixIterator) Key() (key []byte) {
163163
}
164164

165165
key = pi.iter.Key()
166-
key = stripPrefix(key, pi.prefix)
166+
key, ok := bytes.CutPrefix(key, pi.prefix)
167+
if !ok {
168+
panic("should not happen")
169+
}
167170

168171
return
169172
}
@@ -192,15 +195,6 @@ func (pi *prefixIterator) Error() error {
192195
return nil
193196
}
194197

195-
// stripPrefix is copied from github.com/cometbft/cometbft/libs/db/prefix_db.go
196-
func stripPrefix(key, prefix []byte) []byte {
197-
if len(key) < len(prefix) || !bytes.Equal(key[:len(prefix)], prefix) {
198-
panic("should not happen")
199-
}
200-
201-
return key[len(prefix):]
202-
}
203-
204198
// cpIncr wraps the bytes in types.PrefixEndBytes
205199
func cpIncr(bz []byte) []byte {
206200
return types.PrefixEndBytes(bz)

0 commit comments

Comments
 (0)