Skip to content

Commit ef602f6

Browse files
author
Kai Liu
committed
Misc cleanup on performance branch
Summary: Did some trivial stuffs: * Add more comments; * fix compiler's warning messages (uninitialized variables). * etc Test Plan: make check
1 parent 8079dd5 commit ef602f6

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

build_tools/format-diff.sh

-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ fi
4747
# ln -s `git rev-parse --show-toplevel`/build_tools/format-diff.sh $PRE_COMMIT_SCRIPT_PATH
4848
# fi
4949
# fi
50-
5150
set -e
5251

5352
uncommitted_code=`git diff HEAD`
5453

5554
# If there's no uncommitted changes, we assume user are doing post-commit
5655
# format check, in which case we'll check the modified lines from latest commit.
5756
# Otherwise, we'll check format of the uncommitted code only.
58-
format_last_commit=0
5957
if [ -z "$uncommitted_code" ]
6058
then
6159
# Check the format of last commit

db/memtable.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s,
232232
// sequence number since the Seek() call above should have skipped
233233
// all entries with overly large sequence numbers.
234234
const char* entry = iter->key();
235-
uint32_t key_length;
235+
uint32_t key_length = 0;
236236
const char* key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
237237
if (comparator_.comparator.user_comparator()->Compare(
238238
Slice(key_ptr, key_length - 8), key.user_key()) == 0) {
@@ -337,7 +337,7 @@ void MemTable::Update(SequenceNumber seq,
337337
// sequence number since the Seek() call above should have skipped
338338
// all entries with overly large sequence numbers.
339339
const char* entry = iter->key();
340-
uint32_t key_length;
340+
uint32_t key_length = 0;
341341
const char* key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
342342
if (comparator_.comparator.user_comparator()->Compare(
343343
Slice(key_ptr, key_length - 8), lkey.user_key()) == 0) {
@@ -401,7 +401,7 @@ bool MemTable::UpdateCallback(SequenceNumber seq,
401401
// sequence number since the Seek() call above should have skipped
402402
// all entries with overly large sequence numbers.
403403
const char* entry = iter->key();
404-
uint32_t key_length;
404+
uint32_t key_length = 0;
405405
const char* key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
406406
if (comparator_.comparator.user_comparator()->Compare(
407407
Slice(key_ptr, key_length - 8), lkey.user_key()) == 0) {
@@ -466,7 +466,7 @@ size_t MemTable::CountSuccessiveMergeEntries(const LookupKey& key) {
466466

467467
for (; iter->Valid(); iter->Next()) {
468468
const char* entry = iter->key();
469-
uint32_t key_length;
469+
uint32_t key_length = 0;
470470
const char* iter_key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
471471
if (!comparator_.comparator.user_comparator()->Compare(
472472
Slice(iter_key_ptr, key_length - 8), key.user_key()) == 0) {

table/plain_table_reader.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Status PlainTableReader::GetOffset(const Slice& target, const Slice& prefix,
405405
uint64_t prefix_index_offset = bucket_value ^ kSubIndexMask;
406406

407407
const char* index_ptr = sub_index_ + prefix_index_offset;
408-
uint32_t upper_bound;
408+
uint32_t upper_bound = 0;
409409
const uint32_t* base_ptr = (const uint32_t*) GetVarint32Ptr(index_ptr,
410410
index_ptr + 4,
411411
&upper_bound);
@@ -464,17 +464,17 @@ bool PlainTableReader::MayHavePrefix(uint32_t hash) {
464464

465465
Status PlainTableReader::ReadKey(const char* row_ptr, Slice* key,
466466
size_t& bytes_read) {
467-
const char* key_ptr;
467+
const char* key_ptr = nullptr;
468468
bytes_read = 0;
469-
size_t internal_key_size;
469+
size_t internal_key_size = 0;
470470
if (IsFixedLength()) {
471471
internal_key_size = GetFixedInternalKeyLength();
472472
key_ptr = row_ptr;
473473
} else {
474-
uint32_t key_size;
474+
uint32_t key_size = 0;
475475
key_ptr = GetVarint32Ptr(row_ptr, file_data_.data() + data_end_offset_,
476476
&key_size);
477-
internal_key_size = (size_t) key_size;
477+
internal_key_size = (size_t)key_size;
478478
bytes_read = key_ptr - row_ptr;
479479
}
480480
if (row_ptr + internal_key_size >= file_data_.data() + data_end_offset_) {

util/coding_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TEST(Coding, Fixed64) {
4141
const char* p = s.data();
4242
for (int power = 0; power <= 63; power++) {
4343
uint64_t v = static_cast<uint64_t>(1) << power;
44-
uint64_t actual;
44+
uint64_t actual = 0;
4545
actual = DecodeFixed64(p);
4646
ASSERT_EQ(v-1, actual);
4747
p += sizeof(uint64_t);
@@ -90,7 +90,7 @@ TEST(Coding, Varint32) {
9090
const char* limit = p + s.size();
9191
for (uint32_t i = 0; i < (32 * 32); i++) {
9292
uint32_t expected = (i / 32) << (i % 32);
93-
uint32_t actual;
93+
uint32_t actual = 0;
9494
const char* start = p;
9595
p = GetVarint32Ptr(p, limit, &actual);
9696
ASSERT_TRUE(p != nullptr);
@@ -125,7 +125,7 @@ TEST(Coding, Varint64) {
125125
const char* limit = p + s.size();
126126
for (unsigned int i = 0; i < values.size(); i++) {
127127
ASSERT_TRUE(p < limit);
128-
uint64_t actual;
128+
uint64_t actual = 0;
129129
const char* start = p;
130130
p = GetVarint64Ptr(p, limit, &actual);
131131
ASSERT_TRUE(p != nullptr);

util/dynamic_bloom.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class DynamicBloom {
2323

2424
explicit DynamicBloom(uint32_t total_bits, uint32_t num_probes = 6);
2525

26-
// Assuming single threaded access to Add
27-
void Add(const Slice& key) { AddHash(hash_func_(key)); }
26+
// Assuming single threaded access to this function.
27+
void Add(const Slice& key);
2828

29-
// Assuming single threaded access to Add
29+
// Assuming single threaded access to this function.
3030
void AddHash(uint32_t hash);
3131

32-
// Multithreaded access to MayContain is OK
32+
// Multithreaded access to this function is OK
3333
bool MayContain(const Slice& key);
3434

35-
// Multithreaded access to MayContain is OK
35+
// Multithreaded access to this function is OK
3636
bool MayContainHash(uint32_t hash);
3737

3838
private:
@@ -42,6 +42,8 @@ class DynamicBloom {
4242
std::unique_ptr<unsigned char[]> data_;
4343
};
4444

45+
inline void DynamicBloom::Add(const Slice& key) { AddHash(hash_func_(key)); }
46+
4547
inline bool DynamicBloom::MayContain(const Slice& key) {
4648
return (MayContainHash(hash_func_(key)));
4749
}

0 commit comments

Comments
 (0)