Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db01eaf

Browse filesBrowse files
anonrigruyadorno
authored andcommitted
src: improve node:os userInfo performance
PR-URL: #55719 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 5861135 commit db01eaf
Copy full SHA for db01eaf

2 files changed

+28-24Lines changed: 28 additions & 24 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/os.js‎

Copy file name to clipboardExpand all lines: lib/os.js
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,6 @@ function userInfo(options) {
358358
if (user === undefined)
359359
throw new ERR_SYSTEM_ERROR(ctx);
360360

361-
if (isWindows) {
362-
user.uid |= 0;
363-
user.gid |= 0;
364-
}
365-
366361
return user;
367362
}
368363

Collapse file

‎src/node_os.cc‎

Copy file name to clipboardExpand all lines: src/node_os.cc
+28-19Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,29 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
287287
encoding = UTF8;
288288
}
289289

290-
const int err = uv_os_get_passwd(&pwd);
291-
292-
if (err) {
290+
if (const int err = uv_os_get_passwd(&pwd)) {
293291
CHECK_GE(args.Length(), 2);
294292
env->CollectUVExceptionInfo(args[args.Length() - 1], err,
295293
"uv_os_get_passwd");
296294
return args.GetReturnValue().SetUndefined();
297295
}
298296

299-
auto free_passwd = OnScopeLeave([&]() { uv_os_free_passwd(&pwd); });
297+
auto free_passwd = OnScopeLeave([&] { uv_os_free_passwd(&pwd); });
300298

301299
Local<Value> error;
302300

301+
#ifdef _WIN32
302+
Local<Value> uid = Number::New(
303+
env->isolate(),
304+
static_cast<double>(static_cast<int32_t>(pwd.uid & 0xFFFFFFFF)));
305+
Local<Value> gid = Number::New(
306+
env->isolate(),
307+
static_cast<double>(static_cast<int32_t>(pwd.gid & 0xFFFFFFFF)));
308+
#else
303309
Local<Value> uid = Number::New(env->isolate(), pwd.uid);
304310
Local<Value> gid = Number::New(env->isolate(), pwd.gid);
311+
#endif
312+
305313
MaybeLocal<Value> username = StringBytes::Encode(env->isolate(),
306314
pwd.username,
307315
encoding,
@@ -323,21 +331,22 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
323331
return;
324332
}
325333

326-
Local<Object> entry = Object::New(env->isolate());
327-
328-
entry->Set(env->context(), env->uid_string(), uid).Check();
329-
entry->Set(env->context(), env->gid_string(), gid).Check();
330-
entry->Set(env->context(),
331-
env->username_string(),
332-
username.ToLocalChecked()).Check();
333-
entry->Set(env->context(),
334-
env->homedir_string(),
335-
homedir.ToLocalChecked()).Check();
336-
entry->Set(env->context(),
337-
env->shell_string(),
338-
shell.ToLocalChecked()).Check();
339-
340-
args.GetReturnValue().Set(entry);
334+
constexpr size_t kRetLength = 5;
335+
std::array<Local<v8::Name>, kRetLength> names = {env->uid_string(),
336+
env->gid_string(),
337+
env->username_string(),
338+
env->homedir_string(),
339+
env->shell_string()};
340+
std::array values = {uid,
341+
gid,
342+
username.ToLocalChecked(),
343+
homedir.ToLocalChecked(),
344+
shell.ToLocalChecked()};
345+
args.GetReturnValue().Set(Object::New(env->isolate(),
346+
Null(env->isolate()),
347+
names.data(),
348+
values.data(),
349+
kRetLength));
341350
}
342351

343352

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.