From b3fb3440ae64fb56261876cc6cb90770bc0ea843 Mon Sep 17 00:00:00 2001 From: Wiyeong Seo Date: Wed, 9 Sep 2026 17:04:41 +0900 Subject: [PATCH] path: remove `StringPrototypeCharCodeAt` from some methods of `posix` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove `StringPrototypeCharCodeAt` from `posix.resolve`, `posix.normalize`, `posix.parse`. PR-URL: https://github.com/nodejs/node/pull/54668 Refs: https://github.com/nodejs/node/pull/54546 Reviewed-By: Luigi Pinca Reviewed-By: Jordan Harband Reviewed-By: Gürgün Dayıoğlu Reviewed-By: James M Snell --- lib/path.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/path.js b/lib/path.js index 63b037cddfb..658b5d6901d 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1262,8 +1262,7 @@ const posix = { } resolvedPath = `${path}/${resolvedPath}`; - resolvedAbsolute = - StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH; + resolvedAbsolute = path[0] === '/'; } if (!resolvedAbsolute) { @@ -1296,10 +1295,8 @@ const posix = { if (path.length === 0) return '.'; - const isAbsolute = - StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH; - const trailingSeparator = - StringPrototypeCharCodeAt(path, path.length - 1) === CHAR_FORWARD_SLASH; + const isAbsolute = path[0] === '/'; + const trailingSeparator = path[path.length - 1] === '/'; // Normalize the path path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator); @@ -1639,8 +1636,8 @@ const posix = { // Get non-dir info for (; i >= start; --i) { - const code = StringPrototypeCharCodeAt(path, i); - if (code === CHAR_FORWARD_SLASH) { + const char = path[i]; + if (char === '/') { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { @@ -1655,7 +1652,7 @@ const posix = { matchedSlash = false; end = i + 1; } - if (code === CHAR_DOT) { + if (char === '.') { // If this is our first dot, mark it as the start of our extension if (startDot === -1) startDot = i;