save a few redundant container lookups (#5875)
Summary: This PR eliminates repeated lookups in associative or ordered containers when a single lookup suffices. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5875 Differential Revision: D17753172 Pulled By: anand1976 fbshipit-source-id: 796b02b760082521d8c42a1cb65a76bf0e6c1b8e
This commit is contained in:
parent
19a97dd139
commit
da3b2840cb
@ -303,10 +303,7 @@ class VersionBuilder::Rep {
|
||||
levels_[level].added_files.erase(exising);
|
||||
}
|
||||
} else {
|
||||
auto exising = invalid_levels_[level].find(number);
|
||||
if (exising != invalid_levels_[level].end()) {
|
||||
invalid_levels_[level].erase(exising);
|
||||
} else {
|
||||
if (invalid_levels_[level].erase(number) == 0) {
|
||||
// Deleting an non-existing file on invalid level.
|
||||
has_invalid_levels_ = true;
|
||||
}
|
||||
@ -326,8 +323,9 @@ class VersionBuilder::Rep {
|
||||
levels_[level].added_files[f->fd.GetNumber()] = f;
|
||||
} else {
|
||||
uint64_t number = new_file.second.fd.GetNumber();
|
||||
if (invalid_levels_[level].count(number) == 0) {
|
||||
invalid_levels_[level].insert(number);
|
||||
auto& lvls = invalid_levels_[level];
|
||||
if (lvls.count(number) == 0) {
|
||||
lvls.insert(number);
|
||||
} else {
|
||||
// Creating an already existing file on invalid level.
|
||||
has_invalid_levels_ = true;
|
||||
|
@ -473,10 +473,11 @@ Status PessimisticTransaction::LockBatch(WriteBatch* batch,
|
||||
void RecordKey(uint32_t column_family_id, const Slice& key) {
|
||||
std::string key_str = key.ToString();
|
||||
|
||||
auto iter = (keys_)[column_family_id].find(key_str);
|
||||
if (iter == (keys_)[column_family_id].end()) {
|
||||
auto& cfh_keys = keys_[column_family_id];
|
||||
auto iter = cfh_keys.find(key_str);
|
||||
if (iter == cfh_keys.end()) {
|
||||
// key not yet seen, store it.
|
||||
(keys_)[column_family_id].insert({std::move(key_str)});
|
||||
cfh_keys.insert({std::move(key_str)});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ Status TransactionBaseImpl::RollbackToSavePoint() {
|
||||
}
|
||||
if (tracked_keys_iter->second.num_reads == 0 &&
|
||||
tracked_keys_iter->second.num_writes == 0) {
|
||||
tracked_keys_[column_family_id].erase(tracked_keys_iter);
|
||||
cf_tracked_keys.erase(tracked_keys_iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user