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);
|
return Slice(key_, key_size_ - 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Size() { return key_size_; }
|
size_t Size() const { return key_size_; }
|
||||||
|
|
||||||
void Clear() { key_size_ = 0; }
|
void Clear() { key_size_ = 0; }
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ class IterKey {
|
|||||||
char* p = new char[total_size];
|
char* p = new char[total_size];
|
||||||
memcpy(p, key_, shared_len);
|
memcpy(p, key_, shared_len);
|
||||||
|
|
||||||
if (key_ != nullptr && key_ != space_) {
|
if (key_ != space_) {
|
||||||
delete[] key_;
|
delete[] key_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,10 +388,10 @@ class IterKey {
|
|||||||
char space_[32]; // Avoid allocation for short keys
|
char space_[32]; // Avoid allocation for short keys
|
||||||
|
|
||||||
void ResetBuffer() {
|
void ResetBuffer() {
|
||||||
if (key_ != nullptr && key_ != space_) {
|
if (key_ != space_) {
|
||||||
delete[] key_;
|
delete[] key_;
|
||||||
|
key_ = space_;
|
||||||
}
|
}
|
||||||
key_ = space_;
|
|
||||||
buf_size_ = sizeof(space_);
|
buf_size_ = sizeof(space_);
|
||||||
key_size_ = 0;
|
key_size_ = 0;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,8 @@ class WriteBatch : public WriteBatchBase {
|
|||||||
WriteBatch* GetWriteBatch() override { return this; }
|
WriteBatch* GetWriteBatch() override { return this; }
|
||||||
|
|
||||||
// Constructor with a serialized string object
|
// 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:
|
private:
|
||||||
friend class WriteBatchInternal;
|
friend class WriteBatchInternal;
|
||||||
|
@ -614,19 +614,18 @@ class PosixWritableFile : public WritableFile {
|
|||||||
virtual Status Append(const Slice& data) override {
|
virtual Status Append(const Slice& data) override {
|
||||||
const char* src = data.data();
|
const char* src = data.data();
|
||||||
size_t left = data.size();
|
size_t left = data.size();
|
||||||
Status s;
|
while (left != 0) {
|
||||||
while (left != 0) {
|
ssize_t done = write(fd_, src, left);
|
||||||
ssize_t done = write(fd_, src, left);
|
if (done < 0) {
|
||||||
if (done < 0) {
|
if (errno == EINTR) {
|
||||||
if (errno == EINTR) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return IOError(filename_, errno);
|
|
||||||
}
|
}
|
||||||
left -= done;
|
return IOError(filename_, errno);
|
||||||
src += done;
|
|
||||||
}
|
}
|
||||||
filesize_ += data.size();
|
left -= done;
|
||||||
|
src += done;
|
||||||
|
}
|
||||||
|
filesize_ += data.size();
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user