From 28e6d238be73e743c963fc0a26395b783a7565e2 Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Thu, 9 May 2019 14:00:07 -0700 Subject: [PATCH] Switch to using C++ 11 override specifier. PiperOrigin-RevId: 247491163 --- db/c.cc | 22 +++++++++--------- db/db_impl.cc | 2 +- db/db_impl.h | 25 ++++++++++---------- db/db_iter.cc | 20 ++++++++-------- db/db_test.cc | 46 ++++++++++++++++++------------------- db/dbformat.h | 16 ++++++------- db/dumpfile.cc | 6 ++--- db/leveldbutil.cc | 8 +++---- db/log_test.cc | 14 +++++------ db/repair.cc | 2 +- db/version_set.cc | 20 ++++++++-------- helpers/memenv/memenv.cc | 24 +++++++++---------- table/block.cc | 18 +++++++-------- table/filter_block_test.cc | 6 ++--- table/merger.cc | 20 ++++++++-------- table/table_test.cc | 26 ++++++++++----------- table/two_level_iterator.cc | 20 ++++++++-------- util/bloom.cc | 6 ++--- util/cache.cc | 20 ++++++++-------- 19 files changed, 161 insertions(+), 160 deletions(-) diff --git a/db/c.cc b/db/c.cc index e0f3367..1f6fd64 100644 --- a/db/c.cc +++ b/db/c.cc @@ -84,17 +84,17 @@ struct leveldb_filelock_t { }; struct leveldb_comparator_t : public Comparator { - virtual ~leveldb_comparator_t() { (*destructor_)(state_); } + ~leveldb_comparator_t() override { (*destructor_)(state_); } - virtual int Compare(const Slice& a, const Slice& b) const { + int Compare(const Slice& a, const Slice& b) const override { return (*compare_)(state_, a.data(), a.size(), b.data(), b.size()); } - virtual const char* Name() const { return (*name_)(state_); } + const char* Name() const override { return (*name_)(state_); } // No-ops since the C binding does not support key shortening methods. - virtual void FindShortestSeparator(std::string*, const Slice&) const {} - virtual void FindShortSuccessor(std::string* key) const {} + void FindShortestSeparator(std::string*, const Slice&) const override {} + void FindShortSuccessor(std::string* key) const override {} void* state_; void (*destructor_)(void*); @@ -104,11 +104,11 @@ struct leveldb_comparator_t : public Comparator { }; struct leveldb_filterpolicy_t : public FilterPolicy { - virtual ~leveldb_filterpolicy_t() { (*destructor_)(state_); } + ~leveldb_filterpolicy_t() override { (*destructor_)(state_); } - virtual const char* Name() const { return (*name_)(state_); } + const char* Name() const override { return (*name_)(state_); } - virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const { + void CreateFilter(const Slice* keys, int n, std::string* dst) const override { std::vector key_pointers(n); std::vector key_sizes(n); for (int i = 0; i < n; i++) { @@ -121,7 +121,7 @@ struct leveldb_filterpolicy_t : public FilterPolicy { free(filter); } - virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const { + bool KeyMayMatch(const Slice& key, const Slice& filter) const override { return (*key_match_)(state_, key.data(), key.size(), filter.data(), filter.size()); } @@ -345,10 +345,10 @@ void leveldb_writebatch_iterate(const leveldb_writebatch_t* b, void* state, void* state_; void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen); void (*deleted_)(void*, const char* k, size_t klen); - virtual void Put(const Slice& key, const Slice& value) { + void Put(const Slice& key, const Slice& value) override { (*put_)(state_, key.data(), key.size(), value.data(), value.size()); } - virtual void Delete(const Slice& key) { + void Delete(const Slice& key) override { (*deleted_)(state_, key.data(), key.size()); } }; diff --git a/db/db_impl.cc b/db/db_impl.cc index 82be594..22c0d53 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -376,7 +376,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, bool last_log, Logger* info_log; const char* fname; Status* status; // null if options_.paranoid_checks==false - virtual void Corruption(size_t bytes, const Status& s) { + void Corruption(size_t bytes, const Status& s) override { Log(info_log, "%s%s: dropping %d bytes; %s", (this->status == nullptr ? "(ignoring error) " : ""), fname, static_cast(bytes), s.ToString().c_str()); diff --git a/db/db_impl.h b/db/db_impl.h index ae87d6e..a3f1ed1 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -33,20 +33,21 @@ class DBImpl : public DB { DBImpl(const DBImpl&) = delete; DBImpl& operator=(const DBImpl&) = delete; - virtual ~DBImpl(); + ~DBImpl() override; // Implementations of the DB interface - virtual Status Put(const WriteOptions&, const Slice& key, const Slice& value); - virtual Status Delete(const WriteOptions&, const Slice& key); - virtual Status Write(const WriteOptions& options, WriteBatch* updates); - virtual Status Get(const ReadOptions& options, const Slice& key, - std::string* value); - virtual Iterator* NewIterator(const ReadOptions&); - virtual const Snapshot* GetSnapshot(); - virtual void ReleaseSnapshot(const Snapshot* snapshot); - virtual bool GetProperty(const Slice& property, std::string* value); - virtual void GetApproximateSizes(const Range* range, int n, uint64_t* sizes); - virtual void CompactRange(const Slice* begin, const Slice* end); + Status Put(const WriteOptions&, const Slice& key, + const Slice& value) override; + Status Delete(const WriteOptions&, const Slice& key) override; + Status Write(const WriteOptions& options, WriteBatch* updates) override; + Status Get(const ReadOptions& options, const Slice& key, + std::string* value) override; + Iterator* NewIterator(const ReadOptions&) override; + const Snapshot* GetSnapshot() override; + void ReleaseSnapshot(const Snapshot* snapshot) override; + bool GetProperty(const Slice& property, std::string* value) override; + void GetApproximateSizes(const Range* range, int n, uint64_t* sizes) override; + void CompactRange(const Slice* begin, const Slice* end) override; // Extra methods (for testing) that are not in the public DB interface diff --git a/db/db_iter.cc b/db/db_iter.cc index 6e52550..98715a9 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -59,17 +59,17 @@ class DBIter : public Iterator { DBIter(const DBIter&) = delete; DBIter& operator=(const DBIter&) = delete; - virtual ~DBIter() { delete iter_; } - virtual bool Valid() const { return valid_; } - virtual Slice key() const { + ~DBIter() override { delete iter_; } + bool Valid() const override { return valid_; } + Slice key() const override { assert(valid_); return (direction_ == kForward) ? ExtractUserKey(iter_->key()) : saved_key_; } - virtual Slice value() const { + Slice value() const override { assert(valid_); return (direction_ == kForward) ? iter_->value() : saved_value_; } - virtual Status status() const { + Status status() const override { if (status_.ok()) { return iter_->status(); } else { @@ -77,11 +77,11 @@ class DBIter : public Iterator { } } - virtual void Next(); - virtual void Prev(); - virtual void Seek(const Slice& target); - virtual void SeekToFirst(); - virtual void SeekToLast(); + void Next() override; + void Prev() override; + void Seek(const Slice& target) override; + void SeekToFirst() override; + void SeekToLast() override; private: void FindNextUserEntry(bool skipping, std::string* skip); diff --git a/db/db_test.cc b/db/db_test.cc index 1da8db2..9a8faf1 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -210,9 +210,9 @@ class SpecialEnv : public EnvWrapper { public: CountingFile(RandomAccessFile* target, AtomicCounter* counter) : target_(target), counter_(counter) {} - virtual ~CountingFile() { delete target_; } - virtual Status Read(uint64_t offset, size_t n, Slice* result, - char* scratch) const { + ~CountingFile() override { delete target_; } + Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { counter_->Increment(); return target_->Read(offset, n, result, scratch); } @@ -1504,14 +1504,14 @@ TEST(DBTest, Fflush_Issue474) { TEST(DBTest, ComparatorCheck) { class NewComparator : public Comparator { public: - virtual const char* Name() const { return "leveldb.NewComparator"; } - virtual int Compare(const Slice& a, const Slice& b) const { + const char* Name() const override { return "leveldb.NewComparator"; } + int Compare(const Slice& a, const Slice& b) const override { return BytewiseComparator()->Compare(a, b); } - virtual void FindShortestSeparator(std::string* s, const Slice& l) const { + void FindShortestSeparator(std::string* s, const Slice& l) const override { BytewiseComparator()->FindShortestSeparator(s, l); } - virtual void FindShortSuccessor(std::string* key) const { + void FindShortSuccessor(std::string* key) const override { BytewiseComparator()->FindShortSuccessor(key); } }; @@ -1527,15 +1527,15 @@ TEST(DBTest, ComparatorCheck) { TEST(DBTest, CustomComparator) { class NumberComparator : public Comparator { public: - virtual const char* Name() const { return "test.NumberComparator"; } - virtual int Compare(const Slice& a, const Slice& b) const { + const char* Name() const override { return "test.NumberComparator"; } + int Compare(const Slice& a, const Slice& b) const override { return ToNumber(a) - ToNumber(b); } - virtual void FindShortestSeparator(std::string* s, const Slice& l) const { + void FindShortestSeparator(std::string* s, const Slice& l) const override { ToNumber(*s); // Check format ToNumber(l); // Check format } - virtual void FindShortSuccessor(std::string* key) const { + void FindShortSuccessor(std::string* key) const override { ToNumber(*key); // Check format } @@ -2060,10 +2060,10 @@ class ModelDB : public DB { class Handler : public WriteBatch::Handler { public: KVMap* map_; - virtual void Put(const Slice& key, const Slice& value) { + void Put(const Slice& key, const Slice& value) override { (*map_)[key.ToString()] = value.ToString(); } - virtual void Delete(const Slice& key) { map_->erase(key.ToString()); } + void Delete(const Slice& key) override { map_->erase(key.ToString()); } }; Handler handler; handler.map_ = &map_; @@ -2085,26 +2085,26 @@ class ModelDB : public DB { public: ModelIter(const KVMap* map, bool owned) : map_(map), owned_(owned), iter_(map_->end()) {} - ~ModelIter() { + ~ModelIter() override { if (owned_) delete map_; } - virtual bool Valid() const { return iter_ != map_->end(); } - virtual void SeekToFirst() { iter_ = map_->begin(); } - virtual void SeekToLast() { + bool Valid() const override { return iter_ != map_->end(); } + void SeekToFirst() override { iter_ = map_->begin(); } + void SeekToLast() override { if (map_->empty()) { iter_ = map_->end(); } else { iter_ = map_->find(map_->rbegin()->first); } } - virtual void Seek(const Slice& k) { + void Seek(const Slice& k) override { iter_ = map_->lower_bound(k.ToString()); } - virtual void Next() { ++iter_; } - virtual void Prev() { --iter_; } - virtual Slice key() const { return iter_->first; } - virtual Slice value() const { return iter_->second; } - virtual Status status() const { return Status::OK(); } + void Next() override { ++iter_; } + void Prev() override { --iter_; } + Slice key() const override { return iter_->first; } + Slice value() const override { return iter_->second; } + Status status() const override { return Status::OK(); } private: const KVMap* const map_; diff --git a/db/dbformat.h b/db/dbformat.h index f990040..abcb489 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -103,11 +103,11 @@ class InternalKeyComparator : public Comparator { public: explicit InternalKeyComparator(const Comparator* c) : user_comparator_(c) {} - virtual const char* Name() const; - virtual int Compare(const Slice& a, const Slice& b) const; - virtual void FindShortestSeparator(std::string* start, - const Slice& limit) const; - virtual void FindShortSuccessor(std::string* key) const; + const char* Name() const override; + int Compare(const Slice& a, const Slice& b) const override; + void FindShortestSeparator(std::string* start, + const Slice& limit) const override; + void FindShortSuccessor(std::string* key) const override; const Comparator* user_comparator() const { return user_comparator_; } @@ -121,9 +121,9 @@ class InternalFilterPolicy : public FilterPolicy { public: explicit InternalFilterPolicy(const FilterPolicy* p) : user_policy_(p) {} - virtual const char* Name() const; - virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const; - virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const; + const char* Name() const override; + void CreateFilter(const Slice* keys, int n, std::string* dst) const override; + bool KeyMayMatch(const Slice& key, const Slice& filter) const override; }; // Modules in this directory should keep internal keys wrapped inside diff --git a/db/dumpfile.cc b/db/dumpfile.cc index 9d22d58..77d5900 100644 --- a/db/dumpfile.cc +++ b/db/dumpfile.cc @@ -38,7 +38,7 @@ bool GuessType(const std::string& fname, FileType* type) { // Notified when log reader encounters corruption. class CorruptionReporter : public log::Reader::Reporter { public: - virtual void Corruption(size_t bytes, const Status& status) { + void Corruption(size_t bytes, const Status& status) override { std::string r = "corruption: "; AppendNumberTo(&r, bytes); r += " bytes; "; @@ -74,7 +74,7 @@ Status PrintLogContents(Env* env, const std::string& fname, // Called on every item found in a WriteBatch. class WriteBatchItemPrinter : public WriteBatch::Handler { public: - virtual void Put(const Slice& key, const Slice& value) { + void Put(const Slice& key, const Slice& value) override { std::string r = " put '"; AppendEscapedStringTo(&r, key); r += "' '"; @@ -82,7 +82,7 @@ class WriteBatchItemPrinter : public WriteBatch::Handler { r += "'\n"; dst_->Append(r); } - virtual void Delete(const Slice& key) { + void Delete(const Slice& key) override { std::string r = " del '"; AppendEscapedStringTo(&r, key); r += "'\n"; diff --git a/db/leveldbutil.cc b/db/leveldbutil.cc index b21cf8e..55cdcc5 100644 --- a/db/leveldbutil.cc +++ b/db/leveldbutil.cc @@ -13,13 +13,13 @@ namespace { class StdoutPrinter : public WritableFile { public: - virtual Status Append(const Slice& data) { + Status Append(const Slice& data) override { fwrite(data.data(), 1, data.size(), stdout); return Status::OK(); } - virtual Status Close() { return Status::OK(); } - virtual Status Flush() { return Status::OK(); } - virtual Status Sync() { return Status::OK(); } + Status Close() override { return Status::OK(); } + Status Flush() override { return Status::OK(); } + Status Sync() override { return Status::OK(); } }; bool HandleDumpCommand(Env* env, char** files, int num) { diff --git a/db/log_test.cc b/db/log_test.cc index 809c418..0e31648 100644 --- a/db/log_test.cc +++ b/db/log_test.cc @@ -161,10 +161,10 @@ class LogTest { private: class StringDest : public WritableFile { public: - virtual Status Close() { return Status::OK(); } - virtual Status Flush() { return Status::OK(); } - virtual Status Sync() { return Status::OK(); } - virtual Status Append(const Slice& slice) { + Status Close() override { return Status::OK(); } + Status Flush() override { return Status::OK(); } + Status Sync() override { return Status::OK(); } + Status Append(const Slice& slice) override { contents_.append(slice.data(), slice.size()); return Status::OK(); } @@ -176,7 +176,7 @@ class LogTest { public: StringSource() : force_error_(false), returned_partial_(false) {} - virtual Status Read(size_t n, Slice* result, char* scratch) { + Status Read(size_t n, Slice* result, char* scratch) override { ASSERT_TRUE(!returned_partial_) << "must not Read() after eof/error"; if (force_error_) { @@ -194,7 +194,7 @@ class LogTest { return Status::OK(); } - virtual Status Skip(uint64_t n) { + Status Skip(uint64_t n) override { if (n > contents_.size()) { contents_.clear(); return Status::NotFound("in-memory file skipped past end"); @@ -213,7 +213,7 @@ class LogTest { class ReportCollector : public Reader::Reporter { public: ReportCollector() : dropped_bytes_(0) {} - virtual void Corruption(size_t bytes, const Status& status) { + void Corruption(size_t bytes, const Status& status) override { dropped_bytes_ += bytes; message_.append(status.ToString()); } diff --git a/db/repair.cc b/db/repair.cc index 3c676ca..d9d12ba 100644 --- a/db/repair.cc +++ b/db/repair.cc @@ -145,7 +145,7 @@ class Repairer { Env* env; Logger* info_log; uint64_t lognum; - virtual void Corruption(size_t bytes, const Status& s) { + void Corruption(size_t bytes, const Status& s) override { // We print error messages for corruption, but continue repairing. Log(info_log, "Log #%llu: dropping %d bytes; %s", (unsigned long long)lognum, static_cast(bytes), diff --git a/db/version_set.cc b/db/version_set.cc index 099fa57..0f8bec1 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -167,19 +167,19 @@ class Version::LevelFileNumIterator : public Iterator { const std::vector* flist) : icmp_(icmp), flist_(flist), index_(flist->size()) { // Marks as invalid } - virtual bool Valid() const { return index_ < flist_->size(); } - virtual void Seek(const Slice& target) { + bool Valid() const override { return index_ < flist_->size(); } + void Seek(const Slice& target) override { index_ = FindFile(icmp_, *flist_, target); } - virtual void SeekToFirst() { index_ = 0; } - virtual void SeekToLast() { + void SeekToFirst() override { index_ = 0; } + void SeekToLast() override { index_ = flist_->empty() ? 0 : flist_->size() - 1; } - virtual void Next() { + void Next() override { assert(Valid()); index_++; } - virtual void Prev() { + void Prev() override { assert(Valid()); if (index_ == 0) { index_ = flist_->size(); // Marks as invalid @@ -187,17 +187,17 @@ class Version::LevelFileNumIterator : public Iterator { index_--; } } - Slice key() const { + Slice key() const override { assert(Valid()); return (*flist_)[index_]->largest.Encode(); } - Slice value() const { + Slice value() const override { assert(Valid()); EncodeFixed64(value_buf_, (*flist_)[index_]->number); EncodeFixed64(value_buf_ + 8, (*flist_)[index_]->file_size); return Slice(value_buf_, sizeof(value_buf_)); } - virtual Status status() const { return Status::OK(); } + Status status() const override { return Status::OK(); } private: const InternalKeyComparator icmp_; @@ -883,7 +883,7 @@ Status VersionSet::LogAndApply(VersionEdit* edit, port::Mutex* mu) { Status VersionSet::Recover(bool* save_manifest) { struct LogReporter : public log::Reader::Reporter { Status* status; - virtual void Corruption(size_t bytes, const Status& s) { + void Corruption(size_t bytes, const Status& s) override { if (this->status->ok()) *this->status = s; } }; diff --git a/helpers/memenv/memenv.cc b/helpers/memenv/memenv.cc index 2d4fbaa..31d2bc0 100644 --- a/helpers/memenv/memenv.cc +++ b/helpers/memenv/memenv.cc @@ -156,9 +156,9 @@ class SequentialFileImpl : public SequentialFile { file_->Ref(); } - ~SequentialFileImpl() { file_->Unref(); } + ~SequentialFileImpl() override { file_->Unref(); } - virtual Status Read(size_t n, Slice* result, char* scratch) { + Status Read(size_t n, Slice* result, char* scratch) override { Status s = file_->Read(pos_, n, result, scratch); if (s.ok()) { pos_ += result->size(); @@ -166,7 +166,7 @@ class SequentialFileImpl : public SequentialFile { return s; } - virtual Status Skip(uint64_t n) { + Status Skip(uint64_t n) override { if (pos_ > file_->Size()) { return Status::IOError("pos_ > file_->Size()"); } @@ -187,10 +187,10 @@ class RandomAccessFileImpl : public RandomAccessFile { public: explicit RandomAccessFileImpl(FileState* file) : file_(file) { file_->Ref(); } - ~RandomAccessFileImpl() { file_->Unref(); } + ~RandomAccessFileImpl() override { file_->Unref(); } - virtual Status Read(uint64_t offset, size_t n, Slice* result, - char* scratch) const { + Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { return file_->Read(offset, n, result, scratch); } @@ -202,13 +202,13 @@ class WritableFileImpl : public WritableFile { public: WritableFileImpl(FileState* file) : file_(file) { file_->Ref(); } - ~WritableFileImpl() { file_->Unref(); } + ~WritableFileImpl() override { file_->Unref(); } - virtual Status Append(const Slice& data) { return file_->Append(data); } + Status Append(const Slice& data) override { return file_->Append(data); } - virtual Status Close() { return Status::OK(); } - virtual Status Flush() { return Status::OK(); } - virtual Status Sync() { return Status::OK(); } + Status Close() override { return Status::OK(); } + Status Flush() override { return Status::OK(); } + Status Sync() override { return Status::OK(); } private: FileState* file_; @@ -216,7 +216,7 @@ class WritableFileImpl : public WritableFile { class NoOpLogger : public Logger { public: - virtual void Logv(const char* format, va_list ap) {} + void Logv(const char* format, va_list ap) override {} }; class InMemoryEnv : public EnvWrapper { diff --git a/table/block.cc b/table/block.cc index ad0ee98..05c600f 100644 --- a/table/block.cc +++ b/table/block.cc @@ -123,23 +123,23 @@ class Block::Iter : public Iterator { assert(num_restarts_ > 0); } - virtual bool Valid() const { return current_ < restarts_; } - virtual Status status() const { return status_; } - virtual Slice key() const { + bool Valid() const override { return current_ < restarts_; } + Status status() const override { return status_; } + Slice key() const override { assert(Valid()); return key_; } - virtual Slice value() const { + Slice value() const override { assert(Valid()); return value_; } - virtual void Next() { + void Next() override { assert(Valid()); ParseNextKey(); } - virtual void Prev() { + void Prev() override { assert(Valid()); // Scan backwards to a restart point before current_ @@ -160,7 +160,7 @@ class Block::Iter : public Iterator { } while (ParseNextKey() && NextEntryOffset() < original); } - virtual void Seek(const Slice& target) { + void Seek(const Slice& target) override { // Binary search in restart array to find the last restart point // with a key < target uint32_t left = 0; @@ -200,12 +200,12 @@ class Block::Iter : public Iterator { } } - virtual void SeekToFirst() { + void SeekToFirst() override { SeekToRestartPoint(0); ParseNextKey(); } - virtual void SeekToLast() { + void SeekToLast() override { SeekToRestartPoint(num_restarts_ - 1); while (ParseNextKey() && NextEntryOffset() < restarts_) { // Keep skipping diff --git a/table/filter_block_test.cc b/table/filter_block_test.cc index 6cdd435..8b33bbd 100644 --- a/table/filter_block_test.cc +++ b/table/filter_block_test.cc @@ -16,16 +16,16 @@ namespace leveldb { // For testing: emit an array with one hash value per key class TestHashFilter : public FilterPolicy { public: - virtual const char* Name() const { return "TestHashFilter"; } + const char* Name() const override { return "TestHashFilter"; } - virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const { + void CreateFilter(const Slice* keys, int n, std::string* dst) const override { for (int i = 0; i < n; i++) { uint32_t h = Hash(keys[i].data(), keys[i].size(), 1); PutFixed32(dst, h); } } - virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const { + bool KeyMayMatch(const Slice& key, const Slice& filter) const override { uint32_t h = Hash(key.data(), key.size(), 1); for (size_t i = 0; i + 4 <= filter.size(); i += 4) { if (h == DecodeFixed32(filter.data() + i)) { diff --git a/table/merger.cc b/table/merger.cc index 1bbc6cf..76441b1 100644 --- a/table/merger.cc +++ b/table/merger.cc @@ -24,11 +24,11 @@ class MergingIterator : public Iterator { } } - virtual ~MergingIterator() { delete[] children_; } + ~MergingIterator() override { delete[] children_; } - virtual bool Valid() const { return (current_ != nullptr); } + bool Valid() const override { return (current_ != nullptr); } - virtual void SeekToFirst() { + void SeekToFirst() override { for (int i = 0; i < n_; i++) { children_[i].SeekToFirst(); } @@ -36,7 +36,7 @@ class MergingIterator : public Iterator { direction_ = kForward; } - virtual void SeekToLast() { + void SeekToLast() override { for (int i = 0; i < n_; i++) { children_[i].SeekToLast(); } @@ -44,7 +44,7 @@ class MergingIterator : public Iterator { direction_ = kReverse; } - virtual void Seek(const Slice& target) { + void Seek(const Slice& target) override { for (int i = 0; i < n_; i++) { children_[i].Seek(target); } @@ -52,7 +52,7 @@ class MergingIterator : public Iterator { direction_ = kForward; } - virtual void Next() { + void Next() override { assert(Valid()); // Ensure that all children are positioned after key(). @@ -78,7 +78,7 @@ class MergingIterator : public Iterator { FindSmallest(); } - virtual void Prev() { + void Prev() override { assert(Valid()); // Ensure that all children are positioned before key(). @@ -107,17 +107,17 @@ class MergingIterator : public Iterator { FindLargest(); } - virtual Slice key() const { + Slice key() const override { assert(Valid()); return current_->key(); } - virtual Slice value() const { + Slice value() const override { assert(Valid()); return current_->value(); } - virtual Status status() const { + Status status() const override { Status status; for (int i = 0; i < n_; i++) { status = children_[i].status(); diff --git a/table/table_test.cc b/table/table_test.cc index 3c63e32..f689a27 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -38,23 +38,23 @@ static std::string Reverse(const Slice& key) { namespace { class ReverseKeyComparator : public Comparator { public: - virtual const char* Name() const { + const char* Name() const override { return "leveldb.ReverseBytewiseComparator"; } - virtual int Compare(const Slice& a, const Slice& b) const { + int Compare(const Slice& a, const Slice& b) const override { return BytewiseComparator()->Compare(Reverse(a), Reverse(b)); } - virtual void FindShortestSeparator(std::string* start, - const Slice& limit) const { + void FindShortestSeparator(std::string* start, + const Slice& limit) const override { std::string s = Reverse(*start); std::string l = Reverse(limit); BytewiseComparator()->FindShortestSeparator(&s, l); *start = Reverse(s); } - virtual void FindShortSuccessor(std::string* key) const { + void FindShortSuccessor(std::string* key) const override { std::string s = Reverse(*key); BytewiseComparator()->FindShortSuccessor(&s); *key = Reverse(s); @@ -89,15 +89,15 @@ struct STLLessThan { class StringSink : public WritableFile { public: - ~StringSink() = default; + ~StringSink() override = default; const std::string& contents() const { return contents_; } - virtual Status Close() { return Status::OK(); } - virtual Status Flush() { return Status::OK(); } - virtual Status Sync() { return Status::OK(); } + Status Close() override { return Status::OK(); } + Status Flush() override { return Status::OK(); } + Status Sync() override { return Status::OK(); } - virtual Status Append(const Slice& data) { + Status Append(const Slice& data) override { contents_.append(data.data(), data.size()); return Status::OK(); } @@ -111,12 +111,12 @@ class StringSource : public RandomAccessFile { StringSource(const Slice& contents) : contents_(contents.data(), contents.size()) {} - virtual ~StringSource() = default; + ~StringSource() override = default; uint64_t Size() const { return contents_.size(); } - virtual Status Read(uint64_t offset, size_t n, Slice* result, - char* scratch) const { + Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { if (offset >= contents_.size()) { return Status::InvalidArgument("invalid Read offset"); } diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index 1fc4626..144790d 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -20,24 +20,24 @@ class TwoLevelIterator : public Iterator { TwoLevelIterator(Iterator* index_iter, BlockFunction block_function, void* arg, const ReadOptions& options); - virtual ~TwoLevelIterator(); + ~TwoLevelIterator() override; - virtual void Seek(const Slice& target); - virtual void SeekToFirst(); - virtual void SeekToLast(); - virtual void Next(); - virtual void Prev(); + void Seek(const Slice& target) override; + void SeekToFirst() override; + void SeekToLast() override; + void Next() override; + void Prev() override; - virtual bool Valid() const { return data_iter_.Valid(); } - virtual Slice key() const { + bool Valid() const override { return data_iter_.Valid(); } + Slice key() const override { assert(Valid()); return data_iter_.key(); } - virtual Slice value() const { + Slice value() const override { assert(Valid()); return data_iter_.value(); } - virtual Status status() const { + Status status() const override { // It'd be nice if status() returned a const Status& instead of a Status if (!index_iter_.status().ok()) { return index_iter_.status(); diff --git a/util/bloom.cc b/util/bloom.cc index 7f97464..87547a7 100644 --- a/util/bloom.cc +++ b/util/bloom.cc @@ -23,9 +23,9 @@ class BloomFilterPolicy : public FilterPolicy { if (k_ > 30) k_ = 30; } - virtual const char* Name() const { return "leveldb.BuiltinBloomFilter2"; } + const char* Name() const override { return "leveldb.BuiltinBloomFilter2"; } - virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const { + void CreateFilter(const Slice* keys, int n, std::string* dst) const override { // Compute bloom filter size (in both bits and bytes) size_t bits = n * bits_per_key_; @@ -53,7 +53,7 @@ class BloomFilterPolicy : public FilterPolicy { } } - virtual bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const { + bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const override { const size_t len = bloom_filter.size(); if (len < 2) return false; diff --git a/util/cache.cc b/util/cache.cc index 0f801cc..12de306 100644 --- a/util/cache.cc +++ b/util/cache.cc @@ -354,37 +354,37 @@ class ShardedLRUCache : public Cache { shard_[s].SetCapacity(per_shard); } } - virtual ~ShardedLRUCache() {} - virtual Handle* Insert(const Slice& key, void* value, size_t charge, - void (*deleter)(const Slice& key, void* value)) { + ~ShardedLRUCache() override {} + Handle* Insert(const Slice& key, void* value, size_t charge, + void (*deleter)(const Slice& key, void* value)) override { const uint32_t hash = HashSlice(key); return shard_[Shard(hash)].Insert(key, hash, value, charge, deleter); } - virtual Handle* Lookup(const Slice& key) { + Handle* Lookup(const Slice& key) override { const uint32_t hash = HashSlice(key); return shard_[Shard(hash)].Lookup(key, hash); } - virtual void Release(Handle* handle) { + void Release(Handle* handle) override { LRUHandle* h = reinterpret_cast(handle); shard_[Shard(h->hash)].Release(handle); } - virtual void Erase(const Slice& key) { + void Erase(const Slice& key) override { const uint32_t hash = HashSlice(key); shard_[Shard(hash)].Erase(key, hash); } - virtual void* Value(Handle* handle) { + void* Value(Handle* handle) override { return reinterpret_cast(handle)->value; } - virtual uint64_t NewId() { + uint64_t NewId() override { MutexLock l(&id_mutex_); return ++(last_id_); } - virtual void Prune() { + void Prune() override { for (int s = 0; s < kNumShards; s++) { shard_[s].Prune(); } } - virtual size_t TotalCharge() const { + size_t TotalCharge() const override { size_t total = 0; for (int s = 0; s < kNumShards; s++) { total += shard_[s].TotalCharge();