summaryrefslogtreecommitdiff
path: root/table
diff options
context:
space:
mode:
authorcostan <costan@google.com>2018-04-10 16:18:06 -0700
committerVictor Costan <pwnall@chromium.org>2018-04-10 16:26:43 -0700
commit09217fd0677a4fd9713c7a4d774c494a7d3c1f15 (patch)
tree7b22f6275e16b1cb5059aa726d59e8c5a357c1d5 /table
parent6a3b915166fce75aaf9ac209114a3ad9caa34171 (diff)
downloadleveldb-09217fd0677a4fd9713c7a4d774c494a7d3c1f15.tar.gz
Replace NULL with nullptr in C++ files.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192365747
Diffstat (limited to 'table')
-rw-r--r--table/block.cc16
-rw-r--r--table/filter_block.cc4
-rw-r--r--table/iterator.cc12
-rw-r--r--table/iterator_wrapper.h8
-rw-r--r--table/merger.cc12
-rw-r--r--table/table.cc24
-rw-r--r--table/table_builder.cc12
-rw-r--r--table/table_test.cc22
-rw-r--r--table/two_level_iterator.cc32
9 files changed, 71 insertions, 71 deletions
diff --git a/table/block.cc b/table/block.cc
index 43e402c..6fdfdea 100644
--- a/table/block.cc
+++ b/table/block.cc
@@ -48,13 +48,13 @@ Block::~Block() {
// and the length of the value in "*shared", "*non_shared", and
// "*value_length", respectively. Will not dereference past "limit".
//
-// If any errors are detected, returns NULL. Otherwise, returns a
+// If any errors are detected, returns nullptr. Otherwise, returns a
// pointer to the key delta (just past the three decoded values).
static inline const char* DecodeEntry(const char* p, const char* limit,
uint32_t* shared,
uint32_t* non_shared,
uint32_t* value_length) {
- if (limit - p < 3) return NULL;
+ if (limit - p < 3) return nullptr;
*shared = reinterpret_cast<const unsigned char*>(p)[0];
*non_shared = reinterpret_cast<const unsigned char*>(p)[1];
*value_length = reinterpret_cast<const unsigned char*>(p)[2];
@@ -62,13 +62,13 @@ static inline const char* DecodeEntry(const char* p, const char* limit,
// Fast path: all three values are encoded in one byte each
p += 3;
} else {
- if ((p = GetVarint32Ptr(p, limit, shared)) == NULL) return NULL;
- if ((p = GetVarint32Ptr(p, limit, non_shared)) == NULL) return NULL;
- if ((p = GetVarint32Ptr(p, limit, value_length)) == NULL) return NULL;
+ if ((p = GetVarint32Ptr(p, limit, shared)) == nullptr) return nullptr;
+ if ((p = GetVarint32Ptr(p, limit, non_shared)) == nullptr) return nullptr;
+ if ((p = GetVarint32Ptr(p, limit, value_length)) == nullptr) return nullptr;
}
if (static_cast<uint32_t>(limit - p) < (*non_shared + *value_length)) {
- return NULL;
+ return nullptr;
}
return p;
}
@@ -174,7 +174,7 @@ class Block::Iter : public Iterator {
const char* key_ptr = DecodeEntry(data_ + region_offset,
data_ + restarts_,
&shared, &non_shared, &value_length);
- if (key_ptr == NULL || (shared != 0)) {
+ if (key_ptr == nullptr || (shared != 0)) {
CorruptionError();
return;
}
@@ -237,7 +237,7 @@ class Block::Iter : public Iterator {
// Decode next entry
uint32_t shared, non_shared, value_length;
p = DecodeEntry(p, limit, &shared, &non_shared, &value_length);
- if (p == NULL || key_.size() < shared) {
+ if (p == nullptr || key_.size() < shared) {
CorruptionError();
return false;
} else {
diff --git a/table/filter_block.cc b/table/filter_block.cc
index 1ed5134..ce0aa04 100644
--- a/table/filter_block.cc
+++ b/table/filter_block.cc
@@ -78,8 +78,8 @@ void FilterBlockBuilder::GenerateFilter() {
FilterBlockReader::FilterBlockReader(const FilterPolicy* policy,
const Slice& contents)
: policy_(policy),
- data_(NULL),
- offset_(NULL),
+ data_(nullptr),
+ offset_(nullptr),
num_(0),
base_lg_(0) {
size_t n = contents.size();
diff --git a/table/iterator.cc b/table/iterator.cc
index 3d1c87f..aff0e59 100644
--- a/table/iterator.cc
+++ b/table/iterator.cc
@@ -7,14 +7,14 @@
namespace leveldb {
Iterator::Iterator() {
- cleanup_.function = NULL;
- cleanup_.next = NULL;
+ cleanup_.function = nullptr;
+ cleanup_.next = nullptr;
}
Iterator::~Iterator() {
- if (cleanup_.function != NULL) {
+ if (cleanup_.function != nullptr) {
(*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
- for (Cleanup* c = cleanup_.next; c != NULL; ) {
+ for (Cleanup* c = cleanup_.next; c != nullptr; ) {
(*c->function)(c->arg1, c->arg2);
Cleanup* next = c->next;
delete c;
@@ -24,9 +24,9 @@ Iterator::~Iterator() {
}
void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
- assert(func != NULL);
+ assert(func != nullptr);
Cleanup* c;
- if (cleanup_.function == NULL) {
+ if (cleanup_.function == nullptr) {
c = &cleanup_;
} else {
c = new Cleanup;
diff --git a/table/iterator_wrapper.h b/table/iterator_wrapper.h
index f410c3f..f1814ca 100644
--- a/table/iterator_wrapper.h
+++ b/table/iterator_wrapper.h
@@ -16,8 +16,8 @@ namespace leveldb {
// cache locality.
class IteratorWrapper {
public:
- IteratorWrapper(): iter_(NULL), valid_(false) { }
- explicit IteratorWrapper(Iterator* iter): iter_(NULL) {
+ IteratorWrapper(): iter_(nullptr), valid_(false) { }
+ explicit IteratorWrapper(Iterator* iter): iter_(nullptr) {
Set(iter);
}
~IteratorWrapper() { delete iter_; }
@@ -28,7 +28,7 @@ class IteratorWrapper {
void Set(Iterator* iter) {
delete iter_;
iter_ = iter;
- if (iter_ == NULL) {
+ if (iter_ == nullptr) {
valid_ = false;
} else {
Update();
@@ -40,7 +40,7 @@ class IteratorWrapper {
bool Valid() const { return valid_; }
Slice key() const { assert(Valid()); return key_; }
Slice value() const { assert(Valid()); return iter_->value(); }
- // Methods below require iter() != NULL
+ // Methods below require iter() != nullptr
Status status() const { assert(iter_); return iter_->status(); }
void Next() { assert(iter_); iter_->Next(); Update(); }
void Prev() { assert(iter_); iter_->Prev(); Update(); }
diff --git a/table/merger.cc b/table/merger.cc
index 2dde4dc..e079680 100644
--- a/table/merger.cc
+++ b/table/merger.cc
@@ -17,7 +17,7 @@ class MergingIterator : public Iterator {
: comparator_(comparator),
children_(new IteratorWrapper[n]),
n_(n),
- current_(NULL),
+ current_(nullptr),
direction_(kForward) {
for (int i = 0; i < n; i++) {
children_[i].Set(children[i]);
@@ -29,7 +29,7 @@ class MergingIterator : public Iterator {
}
virtual bool Valid() const {
- return (current_ != NULL);
+ return (current_ != nullptr);
}
virtual void SeekToFirst() {
@@ -153,11 +153,11 @@ class MergingIterator : public Iterator {
};
void MergingIterator::FindSmallest() {
- IteratorWrapper* smallest = NULL;
+ IteratorWrapper* smallest = nullptr;
for (int i = 0; i < n_; i++) {
IteratorWrapper* child = &children_[i];
if (child->Valid()) {
- if (smallest == NULL) {
+ if (smallest == nullptr) {
smallest = child;
} else if (comparator_->Compare(child->key(), smallest->key()) < 0) {
smallest = child;
@@ -168,11 +168,11 @@ void MergingIterator::FindSmallest() {
}
void MergingIterator::FindLargest() {
- IteratorWrapper* largest = NULL;
+ IteratorWrapper* largest = nullptr;
for (int i = n_-1; i >= 0; i--) {
IteratorWrapper* child = &children_[i];
if (child->Valid()) {
- if (largest == NULL) {
+ if (largest == nullptr) {
largest = child;
} else if (comparator_->Compare(child->key(), largest->key()) > 0) {
largest = child;
diff --git a/table/table.cc b/table/table.cc
index ff73cee..8e737e1 100644
--- a/table/table.cc
+++ b/table/table.cc
@@ -39,7 +39,7 @@ Status Table::Open(const Options& options,
RandomAccessFile* file,
uint64_t size,
Table** table) {
- *table = NULL;
+ *table = nullptr;
if (size < Footer::kEncodedLength) {
return Status::Corruption("file is too short to be an sstable");
}
@@ -74,8 +74,8 @@ Status Table::Open(const Options& options,
rep->metaindex_handle = footer.metaindex_handle();
rep->index_block = index_block;
rep->cache_id = (options.block_cache ? options.block_cache->NewId() : 0);
- rep->filter_data = NULL;
- rep->filter = NULL;
+ rep->filter_data = nullptr;
+ rep->filter = nullptr;
*table = new Table(rep);
(*table)->ReadMeta(footer);
}
@@ -84,7 +84,7 @@ Status Table::Open(const Options& options,
}
void Table::ReadMeta(const Footer& footer) {
- if (rep_->options.filter_policy == NULL) {
+ if (rep_->options.filter_policy == nullptr) {
return; // Do not need any metadata
}
@@ -161,8 +161,8 @@ Iterator* Table::BlockReader(void* arg,
const Slice& index_value) {
Table* table = reinterpret_cast<Table*>(arg);
Cache* block_cache = table->rep_->options.block_cache;
- Block* block = NULL;
- Cache::Handle* cache_handle = NULL;
+ Block* block = nullptr;
+ Cache::Handle* cache_handle = nullptr;
BlockHandle handle;
Slice input = index_value;
@@ -172,13 +172,13 @@ Iterator* Table::BlockReader(void* arg,
if (s.ok()) {
BlockContents contents;
- if (block_cache != NULL) {
+ if (block_cache != nullptr) {
char cache_key_buffer[16];
EncodeFixed64(cache_key_buffer, table->rep_->cache_id);
EncodeFixed64(cache_key_buffer+8, handle.offset());
Slice key(cache_key_buffer, sizeof(cache_key_buffer));
cache_handle = block_cache->Lookup(key);
- if (cache_handle != NULL) {
+ if (cache_handle != nullptr) {
block = reinterpret_cast<Block*>(block_cache->Value(cache_handle));
} else {
s = ReadBlock(table->rep_->file, options, handle, &contents);
@@ -199,10 +199,10 @@ Iterator* Table::BlockReader(void* arg,
}
Iterator* iter;
- if (block != NULL) {
+ if (block != nullptr) {
iter = block->NewIterator(table->rep_->options.comparator);
- if (cache_handle == NULL) {
- iter->RegisterCleanup(&DeleteBlock, block, NULL);
+ if (cache_handle == nullptr) {
+ iter->RegisterCleanup(&DeleteBlock, block, nullptr);
} else {
iter->RegisterCleanup(&ReleaseBlock, block_cache, cache_handle);
}
@@ -228,7 +228,7 @@ Status Table::InternalGet(const ReadOptions& options, const Slice& k,
Slice handle_value = iiter->value();
FilterBlockReader* filter = rep_->filter;
BlockHandle handle;
- if (filter != NULL &&
+ if (filter != nullptr &&
handle.DecodeFrom(&handle_value).ok() &&
!filter->KeyMayMatch(handle.offset(), k)) {
// Not found
diff --git a/table/table_builder.cc b/table/table_builder.cc
index 62002c8..444d4f9 100644
--- a/table/table_builder.cc
+++ b/table/table_builder.cc
@@ -53,7 +53,7 @@ struct TableBuilder::Rep {
index_block(&index_block_options),
num_entries(0),
closed(false),
- filter_block(opt.filter_policy == NULL ? NULL
+ filter_block(opt.filter_policy == nullptr ? nullptr
: new FilterBlockBuilder(opt.filter_policy)),
pending_index_entry(false) {
index_block_options.block_restart_interval = 1;
@@ -62,7 +62,7 @@ struct TableBuilder::Rep {
TableBuilder::TableBuilder(const Options& options, WritableFile* file)
: rep_(new Rep(options, file)) {
- if (rep_->filter_block != NULL) {
+ if (rep_->filter_block != nullptr) {
rep_->filter_block->StartBlock(0);
}
}
@@ -106,7 +106,7 @@ void TableBuilder::Add(const Slice& key, const Slice& value) {
r->pending_index_entry = false;
}
- if (r->filter_block != NULL) {
+ if (r->filter_block != nullptr) {
r->filter_block->AddKey(key);
}
@@ -131,7 +131,7 @@ void TableBuilder::Flush() {
r->pending_index_entry = true;
r->status = r->file->Flush();
}
- if (r->filter_block != NULL) {
+ if (r->filter_block != nullptr) {
r->filter_block->StartBlock(r->offset);
}
}
@@ -205,7 +205,7 @@ Status TableBuilder::Finish() {
BlockHandle filter_block_handle, metaindex_block_handle, index_block_handle;
// Write filter block
- if (ok() && r->filter_block != NULL) {
+ if (ok() && r->filter_block != nullptr) {
WriteRawBlock(r->filter_block->Finish(), kNoCompression,
&filter_block_handle);
}
@@ -213,7 +213,7 @@ Status TableBuilder::Finish() {
// Write metaindex block
if (ok()) {
BlockBuilder meta_index_block(&r->options);
- if (r->filter_block != NULL) {
+ if (r->filter_block != nullptr) {
// Add mapping from "filter.Name" to location of filter data
std::string key = "filter.";
key.append(r->options.filter_policy->Name());
diff --git a/table/table_test.cc b/table/table_test.cc
index abf6e24..e47db3d 100644
--- a/table/table_test.cc
+++ b/table/table_test.cc
@@ -172,7 +172,7 @@ class Constructor {
virtual const KVMap& data() { return data_; }
- virtual DB* db() const { return NULL; } // Overridden in DBConstructor
+ virtual DB* db() const { return nullptr; } // Overridden in DBConstructor
private:
KVMap data_;
@@ -183,13 +183,13 @@ class BlockConstructor: public Constructor {
explicit BlockConstructor(const Comparator* cmp)
: Constructor(cmp),
comparator_(cmp),
- block_(NULL) { }
+ block_(nullptr) { }
~BlockConstructor() {
delete block_;
}
virtual Status FinishImpl(const Options& options, const KVMap& data) {
delete block_;
- block_ = NULL;
+ block_ = nullptr;
BlockBuilder builder(&options);
for (KVMap::const_iterator it = data.begin();
@@ -222,7 +222,7 @@ class TableConstructor: public Constructor {
public:
TableConstructor(const Comparator* cmp)
: Constructor(cmp),
- source_(NULL), table_(NULL) {
+ source_(nullptr), table_(nullptr) {
}
~TableConstructor() {
Reset();
@@ -262,8 +262,8 @@ class TableConstructor: public Constructor {
void Reset() {
delete table_;
delete source_;
- table_ = NULL;
- source_ = NULL;
+ table_ = nullptr;
+ source_ = nullptr;
}
StringSource* source_;
@@ -351,7 +351,7 @@ class DBConstructor: public Constructor {
explicit DBConstructor(const Comparator* cmp)
: Constructor(cmp),
comparator_(cmp) {
- db_ = NULL;
+ db_ = nullptr;
NewDB();
}
~DBConstructor() {
@@ -359,7 +359,7 @@ class DBConstructor: public Constructor {
}
virtual Status FinishImpl(const Options& options, const KVMap& data) {
delete db_;
- db_ = NULL;
+ db_ = nullptr;
NewDB();
for (KVMap::const_iterator it = data.begin();
it != data.end();
@@ -436,11 +436,11 @@ static const int kNumTestArgs = sizeof(kTestArgList) / sizeof(kTestArgList[0]);
class Harness {
public:
- Harness() : constructor_(NULL) { }
+ Harness() : constructor_(nullptr) { }
void Init(const TestArgs& args) {
delete constructor_;
- constructor_ = NULL;
+ constructor_ = nullptr;
options_ = Options();
options_.block_restart_interval = args.restart_interval;
@@ -636,7 +636,7 @@ class Harness {
}
}
- // Returns NULL if not running against a DB
+ // Returns nullptr if not running against a DB
DB* db() const { return constructor_->db(); }
private:
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 {