Skip to content

Commit 0aab159

Browse files
committed
fixup! fs: add c++ fast path for writeFileSync utf8
1 parent f1cf8f2 commit 0aab159

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/node_file.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,8 @@ static void WriteFileUtf8(const FunctionCallbackInfo<Value>& args) {
24892489

24902490
CHECK_GE(args.Length(), 4);
24912491

2492+
CHECK(args[1]->IsString());
2493+
24922494
CHECK(args[2]->IsInt32());
24932495
const int flags = args[2].As<Int32>()->Value();
24942496

@@ -2511,31 +2513,28 @@ static void WriteFileUtf8(const FunctionCallbackInfo<Value>& args) {
25112513
FS_SYNC_TRACE_BEGIN(open);
25122514
file = uv_fs_open(nullptr, &req, *path, flags, mode, nullptr);
25132515
FS_SYNC_TRACE_END(open);
2516+
25142517
if (req.result < 0) {
25152518
uv_fs_req_cleanup(&req);
25162519
// req will be cleaned up by scope leave.
25172520
return env->ThrowUVException(req.result, "open", nullptr, path.out());
25182521
}
25192522
}
25202523

2521-
auto defer_close = OnScopeLeave([file, is_fd, &req]() {
2522-
if (!is_fd) {
2523-
FS_SYNC_TRACE_BEGIN(close);
2524-
CHECK_EQ(0, uv_fs_close(nullptr, &req, file, nullptr));
2525-
FS_SYNC_TRACE_END(close);
2526-
}
2527-
uv_fs_req_cleanup(&req);
2528-
});
2529-
2530-
CHECK(args[1]->IsString());
25312524
node::Utf8Value value(isolate, args[1]);
2532-
25332525
uv_buf_t uvbuf = uv_buf_init(*value, value.length());
25342526

25352527
FS_SYNC_TRACE_BEGIN(write);
25362528
int err = uv_fs_write(nullptr, &req, file, &uvbuf, 1, 0, nullptr);
25372529
FS_SYNC_TRACE_END(write);
25382530

2531+
if (!is_fd) {
2532+
FS_SYNC_TRACE_BEGIN(close);
2533+
CHECK_EQ(0, uv_fs_close(nullptr, &req, file, nullptr));
2534+
FS_SYNC_TRACE_END(close);
2535+
}
2536+
uv_fs_req_cleanup(&req);
2537+
25392538
if (err < 0) {
25402539
return env->ThrowUVException(err, "write");
25412540
}

0 commit comments

Comments
 (0)