diff --git a/HISTORY.md b/HISTORY.md index a40a3b892..a63d9d628 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased ### Public API Change * Users of `Statistics::getHistogramString()` will see fewer histogram buckets and different bucket endpoints. +* `Slice::compare` and BytewiseComparator `Compare` no longer accept `Slice`s containing nullptr. ### New Features * Add Iterator::Refresh(), which allows users to update the iterator state so that they can avoid some initialization costs of recreating iterators. diff --git a/include/rocksdb/slice.h b/include/rocksdb/slice.h index ec33c97e6..1630803b9 100644 --- a/include/rocksdb/slice.h +++ b/include/rocksdb/slice.h @@ -214,16 +214,8 @@ inline bool operator!=(const Slice& x, const Slice& y) { } inline int Slice::compare(const Slice& b) const { - const size_t min_len = (size_ < b.size_) ? size_ : b.size_; - if (min_len == 0) { - if (size_ > 0) { - return 1; - } else if (b.size_ > 0) { - return -1; - } - return 0; - } assert(data_ != nullptr && b.data_ != nullptr); + const size_t min_len = (size_ < b.size_) ? size_ : b.size_; int r = memcmp(data_, b.data_, min_len); if (r == 0) { if (size_ < b.size_) r = -1; diff --git a/table/cuckoo_table_builder_test.cc b/table/cuckoo_table_builder_test.cc index ec282b4b5..93daaca47 100644 --- a/table/cuckoo_table_builder_test.cc +++ b/table/cuckoo_table_builder_test.cc @@ -109,7 +109,11 @@ class CuckooBuilderTest : public testing::Test { expected_locations.begin(); if (key_idx == keys.size()) { // i is not one of the expected locations. Empty bucket. - ASSERT_EQ(read_slice.compare(expected_unused_bucket), 0); + if (read_slice.data() == nullptr) { + ASSERT_EQ(0, expected_unused_bucket.size()); + } else { + ASSERT_EQ(read_slice.compare(expected_unused_bucket), 0); + } } else { keys_found[key_idx] = true; ASSERT_EQ(read_slice.compare(keys[key_idx] + values[key_idx]), 0); diff --git a/utilities/merge_operators/max.cc b/utilities/merge_operators/max.cc index 06e233fe8..5f42e816e 100644 --- a/utilities/merge_operators/max.cc +++ b/utilities/merge_operators/max.cc @@ -25,6 +25,8 @@ class MaxOperator : public MergeOperator { if (merge_in.existing_value) { max = Slice(merge_in.existing_value->data(), merge_in.existing_value->size()); + } else if (max.data() == nullptr) { + max = Slice(); } for (const auto& op : merge_in.operand_list) {