diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-07-16 22:31:28 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-07-19 12:11:42 +0200 |
commit | 2d32a7e90a510044330d55c599ad6c59e92779f5 (patch) | |
tree | 51049bc65d3559f94ce469dd181b27ea20ff87be /src | |
parent | 5e5ffc81fa823221777ab7c9fed33093afdfa876 (diff) | |
download | android-node-v8-2d32a7e90a510044330d55c599ad6c59e92779f5.tar.gz android-node-v8-2d32a7e90a510044330d55c599ad6c59e92779f5.tar.bz2 android-node-v8-2d32a7e90a510044330d55c599ad6c59e92779f5.zip |
src: use offset calc. instead of `req->data` in node_file
A small refactor – this removes one layer of pointer indirection.
(The performance gain is likely negligible, the main point here
being that this encapsulates libuv request management a bit more.)
PR-URL: https://github.com/nodejs/node/pull/21839
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_file.cc | 16 | ||||
-rw-r--r-- | src/node_file.h | 8 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index c62697cf31..8414a22ad4 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -221,7 +221,7 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() { closing_ = true; CloseReq* req = new CloseReq(env(), promise, object()); auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) { - CloseReq* close = static_cast<CloseReq*>(req->data); + CloseReq* close = CloseReq::from_req(req); CHECK_NOT_NULL(close); close->file_handle()->AfterClose(); Isolate* isolate = close->env()->isolate(); @@ -475,7 +475,7 @@ bool FSReqAfterScope::Proceed() { } void AfterNoArgs(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) @@ -483,7 +483,7 @@ void AfterNoArgs(uv_fs_t* req) { } void AfterStat(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { @@ -492,7 +492,7 @@ void AfterStat(uv_fs_t* req) { } void AfterInteger(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) @@ -500,7 +500,7 @@ void AfterInteger(uv_fs_t* req) { } void AfterOpenFileHandle(uv_fs_t* req) { - FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { @@ -510,7 +510,7 @@ void AfterOpenFileHandle(uv_fs_t* req) { } void AfterStringPath(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); MaybeLocal<Value> link; @@ -529,7 +529,7 @@ void AfterStringPath(uv_fs_t* req) { } void AfterStringPtr(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); MaybeLocal<Value> link; @@ -548,7 +548,7 @@ void AfterStringPtr(uv_fs_t* req) { } void AfterScanDir(uv_fs_t* req) { - FSReqBase* req_wrap = static_cast<FSReqBase*>(req->data); + FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqAfterScope after(req_wrap, req); if (after.Proceed()) { diff --git a/src/node_file.h b/src/node_file.h index 6b45dc8817..141d1d42d7 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -68,6 +68,10 @@ class FSReqBase : public ReqWrap<uv_fs_t> { bool use_bigint() const { return use_bigint_; } + static FSReqBase* from_req(uv_fs_t* req) { + return static_cast<FSReqBase*>(ReqWrap::from_req(req)); + } + private: enum encoding encoding_ = UTF8; bool has_data_ = false; @@ -284,6 +288,10 @@ class FileHandle : public AsyncWrap, public StreamBase { void Reject(Local<Value> reason); + static CloseReq* from_req(uv_fs_t* req) { + return static_cast<CloseReq*>(ReqWrap::from_req(req)); + } + private: Persistent<Promise> promise_; Persistent<Value> ref_; |