@@ -95,7 +95,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
|
95 | 95 | StringPrototypeCharCodeAt(res, res.length - 1) !== CHAR_DOT || |
96 | 96 | StringPrototypeCharCodeAt(res, res.length - 2) !== CHAR_DOT) { |
97 | 97 | if (res.length > 2) { |
98 | | -const lastSlashIndex = StringPrototypeLastIndexOf(res, separator); |
| 98 | +const lastSlashIndex = res.length - lastSegmentLength - 1; |
99 | 99 | if (lastSlashIndex === -1) { |
100 | 100 | res = ''; |
101 | 101 | lastSegmentLength = 0; |
@@ -163,6 +163,8 @@ function _format(sep, pathObject) {
|
163 | 163 | return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`; |
164 | 164 | } |
165 | 165 | |
| 166 | +const forwardSlashRegExp = /\//g; |
| 167 | + |
166 | 168 | const win32 = { |
167 | 169 | /** |
168 | 170 | * path.resolve([from ...], to) |
@@ -186,6 +188,14 @@ const win32 = {
|
186 | 188 | } |
187 | 189 | } else if (resolvedDevice.length === 0) { |
188 | 190 | path = process.cwd(); |
| 191 | +// Fast path for current directory |
| 192 | +if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) && |
| 193 | +isPathSeparator(StringPrototypeCharCodeAt(path, 0)))) { |
| 194 | +if (!isWindows) { |
| 195 | +path = StringPrototypeReplace(path, forwardSlashRegExp, '\\'); |
| 196 | +} |
| 197 | +return path; |
| 198 | +} |
189 | 199 | } else { |
190 | 200 | // Windows has the concept of drive-specific current working |
191 | 201 | // directories. If we've resolved a drive letter but not yet an |
@@ -1171,6 +1181,12 @@ const posix = {
|
1171 | 1181 | * @returns {string} |
1172 | 1182 | */ |
1173 | 1183 | resolve(...args) { |
| 1184 | +if (args.length === 0 || (args.length === 1 && (args[0] === '' || args[0] === '.'))) { |
| 1185 | +const cwd = posixCwd(); |
| 1186 | +if (StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH) { |
| 1187 | +return cwd; |
| 1188 | +} |
| 1189 | +} |
1174 | 1190 | let resolvedPath = ''; |
1175 | 1191 | let resolvedAbsolute = false; |
1176 | 1192 | |
|