From 70e20f07b117f3e0046785064dd0660cfd939933 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Mon, 22 Sep 2025 20:40:56 +0800 Subject: [PATCH] refactor: to use std libary func bytes.CutPrefix --- store/prefix/store.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/store/prefix/store.go b/store/prefix/store.go index 26fc0cb50d9a..732b089652e3 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -163,7 +163,10 @@ func (pi *prefixIterator) Key() (key []byte) { } key = pi.iter.Key() - key = stripPrefix(key, pi.prefix) + key, ok := bytes.CutPrefix(key, pi.prefix) + if !ok { + panic("should not happen") + } return } @@ -192,15 +195,6 @@ func (pi *prefixIterator) Error() error { return nil } -// stripPrefix is copied from github.com/cometbft/cometbft/libs/db/prefix_db.go -func stripPrefix(key, prefix []byte) []byte { - if len(key) < len(prefix) || !bytes.Equal(key[:len(prefix)], prefix) { - panic("should not happen") - } - - return key[len(prefix):] -} - // cpIncr wraps the bytes in types.PrefixEndBytes func cpIncr(bz []byte) []byte { return types.PrefixEndBytes(bz)