Skip to content

Commit

Permalink
src: use offset calc. instead of req->data in node_file
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
addaleax committed Jul 19, 2018
1 parent 5e5ffc8 commit 2d32a7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -475,15 +475,15 @@ 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())
req_wrap->Resolve(Undefined(req_wrap->env()->isolate()));
}

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()) {
Expand All @@ -492,15 +492,15 @@ 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())
req_wrap->Resolve(Integer::New(req_wrap->env()->isolate(), req->result));
}

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()) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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()) {
Expand Down
8 changes: 8 additions & 0 deletions src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit 2d32a7e

Please sign in to comment.