From 834b12a8d5fc9c0de113fc6ac82be24d3aa13102 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 18 Sep 2015 20:10:00 +0200 Subject: [PATCH 1/5] made Size() function const because it does not modify data --- db/dbformat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dbformat.h b/db/dbformat.h index 52f18e6c5..a0ddc03ad 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -282,7 +282,7 @@ class IterKey { return Slice(key_, key_size_ - 8); } - size_t Size() { return key_size_; } + size_t Size() const { return key_size_; } void Clear() { key_size_ = 0; } From 5ec129971bbc1c69f476fa908424ae8939d1ef17 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 18 Sep 2015 20:15:20 +0200 Subject: [PATCH 2/5] key_ cannot become nullptr, so no check is needed for that (ignoring the unlikely case that some overrides `operator new throw(std::bad_alloc)` with a function that returns a nullptr) --- db/dbformat.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/dbformat.h b/db/dbformat.h index a0ddc03ad..2f5d59e60 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -302,7 +302,7 @@ class IterKey { char* p = new char[total_size]; memcpy(p, key_, shared_len); - if (key_ != nullptr && key_ != space_) { + if (key_ != space_) { delete[] key_; } @@ -388,10 +388,10 @@ class IterKey { char space_[32]; // Avoid allocation for short keys void ResetBuffer() { - if (key_ != nullptr && key_ != space_) { + if (key_ != space_) { delete[] key_; + key_ = space_; } - key_ = space_; buf_size_ = sizeof(space_); key_size_ = 0; } From 4704833357a8609e7c42df4f337f938a8e870c08 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 18 Sep 2015 20:20:32 +0200 Subject: [PATCH 3/5] pass input string to WriteBatch() by const reference this may lead to copying less data (in case compilers don't optimize away copying the string by themselves) --- include/rocksdb/write_batch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index e0949b51d..d61ff8c0e 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -206,7 +206,7 @@ class WriteBatch : public WriteBatchBase { WriteBatch* GetWriteBatch() override { return this; } // Constructor with a serialized string object - explicit WriteBatch(std::string rep) : save_points_(nullptr), rep_(rep) {} + explicit WriteBatch(const std::string& rep) : save_points_(nullptr), rep_(rep) {} private: friend class WriteBatchInternal; From bbb18c8278b108c58098c9050aa7e93db5824918 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 18 Sep 2015 20:23:50 +0200 Subject: [PATCH 4/5] removed unused variable of type Status, fixed indentation --- util/env_posix.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index b856f1d70..4f35f8ed4 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -614,19 +614,18 @@ class PosixWritableFile : public WritableFile { virtual Status Append(const Slice& data) override { const char* src = data.data(); size_t left = data.size(); - Status s; - while (left != 0) { - ssize_t done = write(fd_, src, left); - if (done < 0) { - if (errno == EINTR) { - continue; - } - return IOError(filename_, errno); + while (left != 0) { + ssize_t done = write(fd_, src, left); + if (done < 0) { + if (errno == EINTR) { + continue; } - left -= done; - src += done; + return IOError(filename_, errno); } - filesize_ += data.size(); + left -= done; + src += done; + } + filesize_ += data.size(); return Status::OK(); } From 624ef456ddb2e88ae16790236a4e8c89b67428da Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 18 Sep 2015 22:03:47 +0200 Subject: [PATCH 5/5] fixed formatting. thanks @4tXJ7f for pointing me at `make format` --- include/rocksdb/write_batch.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index d61ff8c0e..a097f2169 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -206,7 +206,8 @@ class WriteBatch : public WriteBatchBase { WriteBatch* GetWriteBatch() override { return this; } // Constructor with a serialized string object - explicit WriteBatch(const std::string& rep) : save_points_(nullptr), rep_(rep) {} + explicit WriteBatch(const std::string& rep) + : save_points_(nullptr), rep_(rep) {} private: friend class WriteBatchInternal;