diff --git a/lib/path.js b/lib/path.js index 63b037cddfb986..c342c9bd9800d1 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1378,15 +1378,15 @@ const posix = { let lastCommonSep = -1; let i = 0; for (; i < length; i++) { - const fromCode = StringPrototypeCharCodeAt(from, fromStart + i); - if (fromCode !== StringPrototypeCharCodeAt(to, toStart + i)) + const fromChar = from[fromStart + i]; + if (fromChar !== to[toStart + i]) break; - else if (fromCode === CHAR_FORWARD_SLASH) + else if (fromChar === '/') lastCommonSep = i; } if (i === length) { if (toLen > length) { - if (StringPrototypeCharCodeAt(to, toStart + i) === CHAR_FORWARD_SLASH) { + if (to[toStart + i] === '/') { // We get here if `from` is the exact base path for `to`. // For example: from='/foo/bar'; to='/foo/bar/baz' return StringPrototypeSlice(to, toStart + i + 1); @@ -1397,8 +1397,7 @@ const posix = { return StringPrototypeSlice(to, toStart + i); } } else if (fromLen > length) { - if (StringPrototypeCharCodeAt(from, fromStart + i) === - CHAR_FORWARD_SLASH) { + if (from[fromStart + i] === '/') { // We get here if `to` is the exact base path for `from`. // For example: from='/foo/bar/baz'; to='/foo/bar' lastCommonSep = i; @@ -1414,8 +1413,7 @@ const posix = { // Generate the relative path based on the path difference between `to` // and `from`. for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { - if (i === fromEnd || - StringPrototypeCharCodeAt(from, i) === CHAR_FORWARD_SLASH) { + if (i === fromEnd || from[i] === '/') { out += out.length === 0 ? '..' : '/..'; } } @@ -1442,11 +1440,11 @@ const posix = { validateString(path, 'path'); if (path.length === 0) return '.'; - const hasRoot = StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH; + const hasRoot = path[0] === '/'; let end = -1; let matchedSlash = true; for (let i = path.length - 1; i >= 1; --i) { - if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) { + if (path[i] === '/') { if (!matchedSlash) { end = i; break; @@ -1484,8 +1482,8 @@ const posix = { let extIdx = suffix.length - 1; let firstNonSlashEnd = -1; for (let i = path.length - 1; i >= 0; --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) { @@ -1501,7 +1499,7 @@ const posix = { } if (extIdx >= 0) { // Try to match the explicit extension - if (code === StringPrototypeCharCodeAt(suffix, extIdx)) { + if (char === suffix[extIdx]) { if (--extIdx === -1) { // We matched the extension, so mark this as the end of our path // component @@ -1524,7 +1522,7 @@ const posix = { return StringPrototypeSlice(path, start, end); } for (let i = path.length - 1; i >= 0; --i) { - if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) { + if (path[i] === '/') { // 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) {