Skip to content

Commit

Permalink
Allow passing in nullptr to get() to save a bit of performance on p…
Browse files Browse the repository at this point in the history
…ure lookups (#5)

Co-authored-by: Tommaso Checchi <[email protected]>
  • Loading branch information
yabmek-msft and Tomcc authored Dec 20, 2024
1 parent c069804 commit 336b207
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions db/memtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) {
const uint64_t tag = DecodeFixed64(key_ptr + key_length - 8);
switch (static_cast<ValueType>(tag & 0xff)) {
case kTypeValue: {
Slice v = GetLengthPrefixedSlice(key_ptr + key_length);
value->assign(v.data(), v.size());
if (value) {
Slice v = GetLengthPrefixedSlice(key_ptr + key_length);
value->assign(v.data(), v.size());
}
return true;
}
case kTypeDeletion:
Expand Down
2 changes: 1 addition & 1 deletion db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void SaveValue(void* arg, const Slice& ikey, const Slice& v) {
} else {
if (s->ucmp->Compare(parsed_key.user_key, s->user_key) == 0) {
s->state = (parsed_key.type == kTypeValue) ? kFound : kDeleted;
if (s->state == kFound) {
if (s->state == kFound && s->value) {
s->value->assign(v.data(), v.size());
}
}
Expand Down

0 comments on commit 336b207

Please sign in to comment.