From 09217fd0677a4fd9713c7a4d774c494a7d3c1f15 Mon Sep 17 00:00:00 2001 From: costan Date: Tue, 10 Apr 2018 16:18:06 -0700 Subject: Replace NULL with nullptr in C++ files. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192365747 --- table/two_level_iterator.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'table/two_level_iterator.cc') diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index 7822eba..4e6f420 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -46,7 +46,7 @@ class TwoLevelIterator: public Iterator { // It'd be nice if status() returned a const Status& instead of a Status if (!index_iter_.status().ok()) { return index_iter_.status(); - } else if (data_iter_.iter() != NULL && !data_iter_.status().ok()) { + } else if (data_iter_.iter() != nullptr && !data_iter_.status().ok()) { return data_iter_.status(); } else { return status_; @@ -67,8 +67,8 @@ class TwoLevelIterator: public Iterator { const ReadOptions options_; Status status_; IteratorWrapper index_iter_; - IteratorWrapper data_iter_; // May be NULL - // If data_iter_ is non-NULL, then "data_block_handle_" holds the + IteratorWrapper data_iter_; // May be nullptr + // If data_iter_ is non-null, then "data_block_handle_" holds the // "index_value" passed to block_function_ to create the data_iter_. std::string data_block_handle_; }; @@ -82,7 +82,7 @@ TwoLevelIterator::TwoLevelIterator( arg_(arg), options_(options), index_iter_(index_iter), - data_iter_(NULL) { + data_iter_(nullptr) { } TwoLevelIterator::~TwoLevelIterator() { @@ -91,21 +91,21 @@ TwoLevelIterator::~TwoLevelIterator() { void TwoLevelIterator::Seek(const Slice& target) { index_iter_.Seek(target); InitDataBlock(); - if (data_iter_.iter() != NULL) data_iter_.Seek(target); + if (data_iter_.iter() != nullptr) data_iter_.Seek(target); SkipEmptyDataBlocksForward(); } void TwoLevelIterator::SeekToFirst() { index_iter_.SeekToFirst(); InitDataBlock(); - if (data_iter_.iter() != NULL) data_iter_.SeekToFirst(); + if (data_iter_.iter() != nullptr) data_iter_.SeekToFirst(); SkipEmptyDataBlocksForward(); } void TwoLevelIterator::SeekToLast() { index_iter_.SeekToLast(); InitDataBlock(); - if (data_iter_.iter() != NULL) data_iter_.SeekToLast(); + if (data_iter_.iter() != nullptr) data_iter_.SeekToLast(); SkipEmptyDataBlocksBackward(); } @@ -123,42 +123,42 @@ void TwoLevelIterator::Prev() { void TwoLevelIterator::SkipEmptyDataBlocksForward() { - while (data_iter_.iter() == NULL || !data_iter_.Valid()) { + while (data_iter_.iter() == nullptr || !data_iter_.Valid()) { // Move to next block if (!index_iter_.Valid()) { - SetDataIterator(NULL); + SetDataIterator(nullptr); return; } index_iter_.Next(); InitDataBlock(); - if (data_iter_.iter() != NULL) data_iter_.SeekToFirst(); + if (data_iter_.iter() != nullptr) data_iter_.SeekToFirst(); } } void TwoLevelIterator::SkipEmptyDataBlocksBackward() { - while (data_iter_.iter() == NULL || !data_iter_.Valid()) { + while (data_iter_.iter() == nullptr || !data_iter_.Valid()) { // Move to next block if (!index_iter_.Valid()) { - SetDataIterator(NULL); + SetDataIterator(nullptr); return; } index_iter_.Prev(); InitDataBlock(); - if (data_iter_.iter() != NULL) data_iter_.SeekToLast(); + if (data_iter_.iter() != nullptr) data_iter_.SeekToLast(); } } void TwoLevelIterator::SetDataIterator(Iterator* data_iter) { - if (data_iter_.iter() != NULL) SaveError(data_iter_.status()); + if (data_iter_.iter() != nullptr) SaveError(data_iter_.status()); data_iter_.Set(data_iter); } void TwoLevelIterator::InitDataBlock() { if (!index_iter_.Valid()) { - SetDataIterator(NULL); + SetDataIterator(nullptr); } else { Slice handle = index_iter_.value(); - if (data_iter_.iter() != NULL && handle.compare(data_block_handle_) == 0) { + if (data_iter_.iter() != nullptr && handle.compare(data_block_handle_) == 0) { // data_iter_ is already constructed with this iterator, so // no need to change anything } else { -- cgit v1.2.1 From 297e66afc1dda3f3d7a7cc2022030164c302cb7a Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Thu, 2 May 2019 11:01:00 -0700 Subject: Format all files IAW the Google C++ Style Guide. Use clang-format to correct formatting to be in agreement with the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). Doing this simplifies the process of accepting changes. Also fixed a few warnings flagged by clang-tidy. PiperOrigin-RevId: 246350737 --- table/two_level_iterator.cc | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'table/two_level_iterator.cc') diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index 4e6f420..5340a4d 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -15,13 +15,10 @@ namespace { typedef Iterator* (*BlockFunction)(void*, const ReadOptions&, const Slice&); -class TwoLevelIterator: public Iterator { +class TwoLevelIterator : public Iterator { public: - TwoLevelIterator( - Iterator* index_iter, - BlockFunction block_function, - void* arg, - const ReadOptions& options); + TwoLevelIterator(Iterator* index_iter, BlockFunction block_function, + void* arg, const ReadOptions& options); virtual ~TwoLevelIterator(); @@ -31,9 +28,7 @@ class TwoLevelIterator: public Iterator { virtual void Next(); virtual void Prev(); - virtual bool Valid() const { - return data_iter_.Valid(); - } + virtual bool Valid() const { return data_iter_.Valid(); } virtual Slice key() const { assert(Valid()); return data_iter_.key(); @@ -67,26 +62,22 @@ class TwoLevelIterator: public Iterator { const ReadOptions options_; Status status_; IteratorWrapper index_iter_; - IteratorWrapper data_iter_; // May be nullptr + IteratorWrapper data_iter_; // May be nullptr // If data_iter_ is non-null, then "data_block_handle_" holds the // "index_value" passed to block_function_ to create the data_iter_. std::string data_block_handle_; }; -TwoLevelIterator::TwoLevelIterator( - Iterator* index_iter, - BlockFunction block_function, - void* arg, - const ReadOptions& options) +TwoLevelIterator::TwoLevelIterator(Iterator* index_iter, + BlockFunction block_function, void* arg, + const ReadOptions& options) : block_function_(block_function), arg_(arg), options_(options), index_iter_(index_iter), - data_iter_(nullptr) { -} + data_iter_(nullptr) {} -TwoLevelIterator::~TwoLevelIterator() { -} +TwoLevelIterator::~TwoLevelIterator() {} void TwoLevelIterator::Seek(const Slice& target) { index_iter_.Seek(target); @@ -121,7 +112,6 @@ void TwoLevelIterator::Prev() { SkipEmptyDataBlocksBackward(); } - void TwoLevelIterator::SkipEmptyDataBlocksForward() { while (data_iter_.iter() == nullptr || !data_iter_.Valid()) { // Move to next block @@ -158,7 +148,8 @@ void TwoLevelIterator::InitDataBlock() { SetDataIterator(nullptr); } else { Slice handle = index_iter_.value(); - if (data_iter_.iter() != nullptr && handle.compare(data_block_handle_) == 0) { + if (data_iter_.iter() != nullptr && + handle.compare(data_block_handle_) == 0) { // data_iter_ is already constructed with this iterator, so // no need to change anything } else { @@ -171,11 +162,9 @@ void TwoLevelIterator::InitDataBlock() { } // namespace -Iterator* NewTwoLevelIterator( - Iterator* index_iter, - BlockFunction block_function, - void* arg, - const ReadOptions& options) { +Iterator* NewTwoLevelIterator(Iterator* index_iter, + BlockFunction block_function, void* arg, + const ReadOptions& options) { return new TwoLevelIterator(index_iter, block_function, arg, options); } -- cgit v1.2.1 From 24424a1ef2c284f4ec30544a3458023362cbeacd Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Sat, 4 May 2019 17:40:21 -0700 Subject: Style cleanup. 1) Convert iterator-based for loops to C++11 foreach loops. 2) Convert "void operator=" to "T& operator=". 3) Switch from copy operators from private to public deleted. 4) Switch from empty ctors / dtors to "= default" where appropriate. PiperOrigin-RevId: 246679195 --- table/two_level_iterator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'table/two_level_iterator.cc') diff --git a/table/two_level_iterator.cc b/table/two_level_iterator.cc index 5340a4d..1fc4626 100644 --- a/table/two_level_iterator.cc +++ b/table/two_level_iterator.cc @@ -77,7 +77,7 @@ TwoLevelIterator::TwoLevelIterator(Iterator* index_iter, index_iter_(index_iter), data_iter_(nullptr) {} -TwoLevelIterator::~TwoLevelIterator() {} +TwoLevelIterator::~TwoLevelIterator() = default; void TwoLevelIterator::Seek(const Slice& target) { index_iter_.Seek(target); -- cgit v1.2.1 From 28e6d238be73e743c963fc0a26395b783a7565e2 Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Thu, 9 May 2019 14:00:07 -0700 Subject: Switch to using C++ 11 override specifier. PiperOrigin-RevId: 247491163 --- table/two_level_iterator.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'table/two_level_iterator.cc') 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(); -- cgit v1.2.1