Skip to content

Commit

Permalink
Problem: redundant copy in check validate
Browse files Browse the repository at this point in the history
free key

update doc

cleanup
  • Loading branch information
mmsqe committed Jul 2, 2024
1 parent 77bcbfb commit e63dbdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* (versiondb) [#1491](https://github.com/crypto-org-chain/cronos/pull/1491) Free slice data in HasAtVersion.
* [#1489](https://github.com/crypto-org-chain/cronos/pull/1489) Update cometbft to v0.37.7.
* (versiondb) [#1498](https://github.com/crypto-org-chain/cronos/pull/1498) Reduce scope of copying slice data in iterator.

*Jun 18, 2024*

Expand Down Expand Up @@ -33,7 +34,6 @@
* (e2ee)[#1415](https://github.com/crypto-org-chain/cronos/pull/1415) Add batch keys query for e2ee module.
* (e2ee)[#1421](https://github.com/crypto-org-chain/cronos/pull/1421) Validate e2ee key when register.
* [#1437](https://github.com/crypto-org-chain/cronos/pull/1437) Update cometbft and cosmos-sdk dependencies.
* (rpc) [#1467](https://github.com/crypto-org-chain/cronos/pull/1467) Avoid unnecessary tx decode in tx listener.

### Bug Fixes

Expand Down
12 changes: 7 additions & 5 deletions versiondb/tsrocksdb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func newRocksDBIterator(source *grocksdb.Iterator, prefix, start, end []byte, is
} else {
source.Seek(end)
if source.Valid() {
eoakey := moveSliceToBytes(source.Key()) // end or after key
if bytes.Compare(end, eoakey) <= 0 {
eoakey := source.Key() // end or after key
defer eoakey.Free()
if bytes.Compare(end, eoakey.Data()) <= 0 {
source.Prev()
}
} else {
Expand Down Expand Up @@ -75,14 +76,15 @@ func (itr *rocksDBIterator) Valid() bool {
// If key is end or past it, invalid.
start := itr.start
end := itr.end
key := moveSliceToBytes(itr.source.Key())
key := itr.source.Key()
defer key.Free()
if itr.isReverse {
if start != nil && bytes.Compare(key, start) < 0 {
if start != nil && bytes.Compare(key.Data(), start) < 0 {
itr.isInvalid = true
return false
}
} else {
if end != nil && bytes.Compare(end, key) <= 0 {
if end != nil && bytes.Compare(end, key.Data()) <= 0 {
itr.isInvalid = true
return false
}
Expand Down

0 comments on commit e63dbdc

Please sign in to comment.