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>
This commit is contained in:
parent
5e5ffc81fa
commit
2d32a7e90a
@ -221,7 +221,7 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() {
|
|||||||
closing_ = true;
|
closing_ = true;
|
||||||
CloseReq* req = new CloseReq(env(), promise, object());
|
CloseReq* req = new CloseReq(env(), promise, object());
|
||||||
auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) {
|
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);
|
CHECK_NOT_NULL(close);
|
||||||
close->file_handle()->AfterClose();
|
close->file_handle()->AfterClose();
|
||||||
Isolate* isolate = close->env()->isolate();
|
Isolate* isolate = close->env()->isolate();
|
||||||
@ -475,7 +475,7 @@ bool FSReqAfterScope::Proceed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterNoArgs(uv_fs_t* req) {
|
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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
if (after.Proceed())
|
if (after.Proceed())
|
||||||
@ -483,7 +483,7 @@ void AfterNoArgs(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterStat(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
if (after.Proceed()) {
|
if (after.Proceed()) {
|
||||||
@ -492,7 +492,7 @@ void AfterStat(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterInteger(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
if (after.Proceed())
|
if (after.Proceed())
|
||||||
@ -500,7 +500,7 @@ void AfterInteger(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterOpenFileHandle(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
if (after.Proceed()) {
|
if (after.Proceed()) {
|
||||||
@ -510,7 +510,7 @@ void AfterOpenFileHandle(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterStringPath(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
MaybeLocal<Value> link;
|
MaybeLocal<Value> link;
|
||||||
@ -529,7 +529,7 @@ void AfterStringPath(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterStringPtr(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
MaybeLocal<Value> link;
|
MaybeLocal<Value> link;
|
||||||
@ -548,7 +548,7 @@ void AfterStringPtr(uv_fs_t* req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AfterScanDir(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);
|
FSReqAfterScope after(req_wrap, req);
|
||||||
|
|
||||||
if (after.Proceed()) {
|
if (after.Proceed()) {
|
||||||
|
@ -68,6 +68,10 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
|
|||||||
|
|
||||||
bool use_bigint() const { return use_bigint_; }
|
bool use_bigint() const { return use_bigint_; }
|
||||||
|
|
||||||
|
static FSReqBase* from_req(uv_fs_t* req) {
|
||||||
|
return static_cast<FSReqBase*>(ReqWrap::from_req(req));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum encoding encoding_ = UTF8;
|
enum encoding encoding_ = UTF8;
|
||||||
bool has_data_ = false;
|
bool has_data_ = false;
|
||||||
@ -284,6 +288,10 @@ class FileHandle : public AsyncWrap, public StreamBase {
|
|||||||
|
|
||||||
void Reject(Local<Value> reason);
|
void Reject(Local<Value> reason);
|
||||||
|
|
||||||
|
static CloseReq* from_req(uv_fs_t* req) {
|
||||||
|
return static_cast<CloseReq*>(ReqWrap::from_req(req));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Persistent<Promise> promise_;
|
Persistent<Promise> promise_;
|
||||||
Persistent<Value> ref_;
|
Persistent<Value> ref_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user