Merge pull request #727 from jsteemann/micro-optimization
Micro optimizations
This commit is contained in:
commit
0e65693f17
@ -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; }
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -206,7 +206,8 @@ 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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user