Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: redundant copy in check validate (back port: #1498) #1499

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

* (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.

*May 3, 2024*

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
Loading