diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-03-06 20:39:25 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-11 05:59:05 +0300 |
commit | f96bd54dd54c66970e8d268503fc77803cb9dbfc (patch) | |
tree | 89a4e1c2fbdf6ff275a0d9e160001cfc372bc78a /src/node_file.h | |
parent | f3257dd3ead29e620b2bc096d54b07b12ec5c5a3 (diff) |
fs: simplify FSReqBase slightly
Replace the `data_` member of `FSReqBase` by a boolean flag, because
the pointer that `data()` returns is already available through the
`buffer_` member, and set the default size for not requiring an
extra allocation to a more reasonable value, as the input is
usually something like a file path.
PR-URL: https://github.com/nodejs/node/pull/19174
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_file.h')
-rw-r--r-- | src/node_file.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/node_file.h b/src/node_file.h index a65b9f0e5fc..bf277a0e433 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -39,11 +39,11 @@ class FSReqBase : public ReqWrap<uv_fs_t> { encoding_ = encoding; if (data != nullptr) { - CHECK_EQ(data_, nullptr); + CHECK(!has_data_); buffer_.AllocateSufficientStorage(len + 1); buffer_.SetLengthAndZeroTerminate(len); memcpy(*buffer_, data, len); - data_ = *buffer_; + has_data_ = true; } } @@ -54,17 +54,19 @@ class FSReqBase : public ReqWrap<uv_fs_t> { virtual void SetReturnValue(const FunctionCallbackInfo<Value>& args) = 0; const char* syscall() const { return syscall_; } - const char* data() const { return data_; } + const char* data() const { return has_data_ ? *buffer_ : nullptr; } enum encoding encoding() const { return encoding_; } size_t self_size() const override { return sizeof(*this); } private: enum encoding encoding_ = UTF8; + bool has_data_ = false; const char* syscall_ = nullptr; - const char* data_ = nullptr; - MaybeStackBuffer<char> buffer_; + // Typically, the content of buffer_ is something like a file name, so + // something around 64 bytes should be enough. + MaybeStackBuffer<char, 64> buffer_; DISALLOW_COPY_AND_ASSIGN(FSReqBase); }; |