@@ -95,7 +95,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
9595 StringPrototypeCharCodeAt ( res , res . length - 1 ) !== CHAR_DOT ||
9696 StringPrototypeCharCodeAt ( res , res . length - 2 ) !== CHAR_DOT ) {
9797 if ( res . length > 2 ) {
98- const lastSlashIndex = StringPrototypeLastIndexOf ( res , separator ) ;
98+ const lastSlashIndex = res . length - lastSegmentLength - 1 ;
9999 if ( lastSlashIndex === - 1 ) {
100100 res = '' ;
101101 lastSegmentLength = 0 ;
@@ -163,6 +163,8 @@ function _format(sep, pathObject) {
163163 return dir === pathObject . root ? `${ dir } ${ base } ` : `${ dir } ${ sep } ${ base } ` ;
164164}
165165
166+ const forwardSlashRegExp = / \/ / g;
167+
166168const win32 = {
167169 /**
168170 * path.resolve([from ...], to)
@@ -186,6 +188,14 @@ const win32 = {
186188 }
187189 } else if ( resolvedDevice . length === 0 ) {
188190 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+ }
189199 } else {
190200 // Windows has the concept of drive-specific current working
191201 // directories. If we've resolved a drive letter but not yet an
@@ -1171,6 +1181,12 @@ const posix = {
11711181 * @returns {string }
11721182 */
11731183 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+ }
11741190 let resolvedPath = '' ;
11751191 let resolvedAbsolute = false ;
11761192
0 commit comments