summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorChris Mumford <cmumford@google.com>2019-05-03 09:31:18 -0700
committerChris Mumford <cmumford@google.com>2019-05-03 09:48:57 -0700
commit9bd23c767601a2420478eec158927882b879bada (patch)
tree1b40c3712c8d882bab5d339a572e56527c145b56 /util
parentc784d63b931d07895833fb80185b10d44ad63cce (diff)
downloadleveldb-9bd23c767601a2420478eec158927882b879bada.tar.gz
Correct class/structure declaration order.
1. Correct the class/struct declaration order to be IAW the Google C++ style guide[1]. 2. For non-copyable classes, switched from non-implemented private methods to explicitly deleted[2] methods. 3. Minor const and member initialization fixes. [1] https://google.github.io/styleguide/cppguide.html#Declaration_Order [2] http://eel.is/c++draft/dcl.fct.def.delete PiperOrigin-RevId: 246521844
Diffstat (limited to 'util')
-rw-r--r--util/arena.cc6
-rw-r--r--util/arena.h8
-rw-r--r--util/bloom.cc8
-rw-r--r--util/bloom_test.cc10
-rw-r--r--util/cache_test.cc4
-rw-r--r--util/env_posix_test.cc7
-rw-r--r--util/env_test.cc3
-rw-r--r--util/env_windows.cc16
-rw-r--r--util/env_windows_test.cc7
-rw-r--r--util/histogram.h16
10 files changed, 43 insertions, 42 deletions
diff --git a/util/arena.cc b/util/arena.cc
index eadec8a..46e3b2e 100644
--- a/util/arena.cc
+++ b/util/arena.cc
@@ -8,10 +8,8 @@ namespace leveldb {
static const int kBlockSize = 4096;
-Arena::Arena() : memory_usage_(0) {
- alloc_ptr_ = nullptr; // First allocation will allocate a block
- alloc_bytes_remaining_ = 0;
-}
+Arena::Arena()
+ : alloc_ptr_(nullptr), alloc_bytes_remaining_(0), memory_usage_(0) {}
Arena::~Arena() {
for (size_t i = 0; i < blocks_.size(); i++) {
diff --git a/util/arena.h b/util/arena.h
index 624e262..68fc55d 100644
--- a/util/arena.h
+++ b/util/arena.h
@@ -16,6 +16,10 @@ namespace leveldb {
class Arena {
public:
Arena();
+
+ Arena(const Arena&) = delete;
+ Arena& operator=(const Arena&) = delete;
+
~Arena();
// Return a pointer to a newly allocated memory block of "bytes" bytes.
@@ -46,10 +50,6 @@ class Arena {
// TODO(costan): This member is accessed via atomics, but the others are
// accessed without any locking. Is this OK?
std::atomic<size_t> memory_usage_;
-
- // No copying allowed
- Arena(const Arena&);
- void operator=(const Arena&);
};
inline char* Arena::Allocate(size_t bytes) {
diff --git a/util/bloom.cc b/util/bloom.cc
index 097ce7a..7f97464 100644
--- a/util/bloom.cc
+++ b/util/bloom.cc
@@ -15,10 +15,6 @@ static uint32_t BloomHash(const Slice& key) {
}
class BloomFilterPolicy : public FilterPolicy {
- private:
- size_t bits_per_key_;
- size_t k_;
-
public:
explicit BloomFilterPolicy(int bits_per_key) : bits_per_key_(bits_per_key) {
// We intentionally round down to reduce probing cost a little bit
@@ -82,6 +78,10 @@ class BloomFilterPolicy : public FilterPolicy {
}
return true;
}
+
+ private:
+ size_t bits_per_key_;
+ size_t k_;
};
} // namespace
diff --git a/util/bloom_test.cc b/util/bloom_test.cc
index 71c4115..436daa9 100644
--- a/util/bloom_test.cc
+++ b/util/bloom_test.cc
@@ -19,11 +19,6 @@ static Slice Key(int i, char* buffer) {
}
class BloomTest {
- private:
- const FilterPolicy* policy_;
- std::string filter_;
- std::vector<std::string> keys_;
-
public:
BloomTest() : policy_(NewBloomFilterPolicy(10)) {}
@@ -78,6 +73,11 @@ class BloomTest {
}
return result / 10000.0;
}
+
+ private:
+ const FilterPolicy* policy_;
+ std::string filter_;
+ std::vector<std::string> keys_;
};
TEST(BloomTest, EmptyFilter) {
diff --git a/util/cache_test.cc b/util/cache_test.cc
index d5c1a1d..974334b 100644
--- a/util/cache_test.cc
+++ b/util/cache_test.cc
@@ -25,8 +25,6 @@ static int DecodeValue(void* v) { return reinterpret_cast<uintptr_t>(v); }
class CacheTest {
public:
- static CacheTest* current_;
-
static void Deleter(const Slice& key, void* v) {
current_->deleted_keys_.push_back(DecodeKey(key));
current_->deleted_values_.push_back(DecodeValue(v));
@@ -61,6 +59,8 @@ class CacheTest {
}
void Erase(int key) { cache_->Erase(EncodeKey(key)); }
+
+ static CacheTest* current_;
};
CacheTest* CacheTest::current_;
diff --git a/util/env_posix_test.cc b/util/env_posix_test.cc
index 6a2a1fc..4b72934 100644
--- a/util/env_posix_test.cc
+++ b/util/env_posix_test.cc
@@ -14,13 +14,14 @@ static const int kMMapLimit = 4;
class EnvPosixTest {
public:
- Env* env_;
- EnvPosixTest() : env_(Env::Default()) {}
-
static void SetFileLimits(int read_only_file_limit, int mmap_limit) {
EnvPosixTestHelper::SetReadOnlyFDLimit(read_only_file_limit);
EnvPosixTestHelper::SetReadOnlyMMapLimit(mmap_limit);
}
+
+ EnvPosixTest() : env_(Env::Default()) {}
+
+ Env* env_;
};
TEST(EnvPosixTest, TestOpenOnRead) {
diff --git a/util/env_test.cc b/util/env_test.cc
index 3e81261..9e2ad1e 100644
--- a/util/env_test.cc
+++ b/util/env_test.cc
@@ -19,8 +19,9 @@ static const int kDelayMicros = 100000;
class EnvTest {
public:
- Env* env_;
EnvTest() : env_(Env::Default()) {}
+
+ Env* env_;
};
namespace {
diff --git a/util/env_windows.cc b/util/env_windows.cc
index c537938..09e3df6 100644
--- a/util/env_windows.cc
+++ b/util/env_windows.cc
@@ -626,21 +626,19 @@ class WindowsEnv : public Env {
}
private:
- // BGThread() is the body of the background thread
- void BGThread();
-
- std::mutex mu_;
- std::condition_variable bgsignal_;
- bool started_bgthread_;
-
// Entry per Schedule() call
struct BGItem {
void* arg;
void (*function)(void*);
};
- typedef std::deque<BGItem> BGQueue;
- BGQueue queue_;
+ // BGThread() is the body of the background thread
+ void BGThread();
+
+ std::mutex mu_;
+ std::condition_variable bgsignal_;
+ bool started_bgthread_;
+ std::deque<BGItem> queue_;
Limiter mmap_limiter_;
};
diff --git a/util/env_windows_test.cc b/util/env_windows_test.cc
index 4451b9e..3c22133 100644
--- a/util/env_windows_test.cc
+++ b/util/env_windows_test.cc
@@ -14,12 +14,13 @@ static const int kMMapLimit = 4;
class EnvWindowsTest {
public:
- Env* env_;
- EnvWindowsTest() : env_(Env::Default()) {}
-
static void SetFileLimits(int mmap_limit) {
EnvWindowsTestHelper::SetReadOnlyMMapLimit(mmap_limit);
}
+
+ EnvWindowsTest() : env_(Env::Default()) {}
+
+ Env* env_;
};
TEST(EnvWindowsTest, TestOpenOnRead) {
diff --git a/util/histogram.h b/util/histogram.h
index fe281a9..4da60fb 100644
--- a/util/histogram.h
+++ b/util/histogram.h
@@ -21,20 +21,22 @@ class Histogram {
std::string ToString() const;
private:
+ enum { kNumBuckets = 154 };
+
+ double Median() const;
+ double Percentile(double p) const;
+ double Average() const;
+ double StandardDeviation() const;
+
+ static const double kBucketLimit[kNumBuckets];
+
double min_;
double max_;
double num_;
double sum_;
double sum_squares_;
- enum { kNumBuckets = 154 };
- static const double kBucketLimit[kNumBuckets];
double buckets_[kNumBuckets];
-
- double Median() const;
- double Percentile(double p) const;
- double Average() const;
- double StandardDeviation() const;
};
} // namespace leveldb