From b77afc0ec007de65825020a70f91ae942eaba2d9 Mon Sep 17 00:00:00 2001 From: jiho Date: Sat, 6 Sep 2025 18:13:31 +0900 Subject: [PATCH 1/2] path: refactor path joining logic for clarity and performance --- lib/path.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/path.js b/lib/path.js index be6fd8b24ac8bf..18e0b67ac2090a 100644 --- a/lib/path.js +++ b/lib/path.js @@ -506,21 +506,20 @@ const win32 = { if (args.length === 0) return '.'; - let joined; - let firstPart; + const path = []; for (let i = 0; i < args.length; ++i) { const arg = args[i]; validateString(arg, 'path'); if (arg.length > 0) { - if (joined === undefined) - joined = firstPart = arg; - else - joined += `\\${arg}`; + path.push(arg); } } - if (joined === undefined) + if (path.length === 0) return '.'; + + const firstPart = path[0]; + let joined = ArrayPrototypeJoin(path, '\\'); // Make sure that the joined path doesn't start with two slashes, because // normalize() will mistake it for a UNC path then. From f1f2e0552af7058093afd35ac59243543514e6a4 Mon Sep 17 00:00:00 2001 From: jiho Date: Sat, 6 Sep 2025 18:38:30 +0900 Subject: [PATCH 2/2] refactor: use ArrayPrototypePush for path array manipulation --- lib/path.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/path.js b/lib/path.js index 18e0b67ac2090a..63b037cddfb986 100644 --- a/lib/path.js +++ b/lib/path.js @@ -24,6 +24,7 @@ const { ArrayPrototypeIncludes, ArrayPrototypeJoin, + ArrayPrototypePush, ArrayPrototypeSlice, FunctionPrototypeBind, StringPrototypeCharCodeAt, @@ -511,13 +512,13 @@ const win32 = { const arg = args[i]; validateString(arg, 'path'); if (arg.length > 0) { - path.push(arg); + ArrayPrototypePush(path, arg); } } if (path.length === 0) return '.'; - + const firstPart = path[0]; let joined = ArrayPrototypeJoin(path, '\\');