Skip to content

Commit

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

update doc

cleanup
  • Loading branch information
mmsqe authored Jul 3, 2024
1 parent b8c2d64 commit 53e4469
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* (versiondb) [#1379](https://github.com/crypto-org-chain/cronos/pull/1379) Flush versiondb when graceful shutdown, make rocksdb upgrade smooth.
* (versiondb) [#1491](https://github.com/crypto-org-chain/cronos/pull/1491) Free slice data in HasAtVersion.
* (versiondb) [#1498](https://github.com/crypto-org-chain/cronos/pull/1498) Reduce scope of copying slice data in iterator.

### 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 53e4469

Please sign in to comment.