From 6aff340c425a56cb3cf4c3b00b2bd68c48365857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 23 Jul 2017 21:48:33 +0200 Subject: [PATCH 1/5] path: remove unnecessary string copy At this line, `path` has a length of 2, so `path.slice(0, 2) === path`. --- lib/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/path.js b/lib/path.js index 001152866ffc35..93eda87dcca1d0 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1049,7 +1049,7 @@ const win32 = { } else { // `path` contains just a drive root, exit early to avoid // unnecessary work - ret.root = ret.dir = path.slice(0, 2); + ret.root = ret.dir = path; return ret; } } From 530f3009b015bd187face642053c266b43afee35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 23 Jul 2017 21:55:55 +0200 Subject: [PATCH 2/5] path: remove unnecessary string copy --- lib/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/path.js b/lib/path.js index 93eda87dcca1d0..c1095733ec2a50 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1040,7 +1040,7 @@ const win32 = { if (len === 3) { // `path` contains just a drive root, exit early to avoid // unnecessary work - ret.root = ret.dir = path.slice(0, 3); + ret.root = ret.dir = path; return ret; } isAbsolute = true; From 8a07118b61822b636b5d010017a1c22521a72b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 24 Jul 2017 11:57:05 +0200 Subject: [PATCH 3/5] More optimizations --- lib/path.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/path.js b/lib/path.js index c1095733ec2a50..019843f3eb48fe 100644 --- a/lib/path.js +++ b/lib/path.js @@ -788,7 +788,9 @@ const win32 = { } } } else if (code === 47/*/*/ || code === 92/*\*/) { - return path[0]; + // `path` contains just a path separator, exit early to avoid + // unnecessary work + return path; } for (var i = len - 1; i >= offset; --i) { @@ -1057,7 +1059,7 @@ const win32 = { } else if (code === 47/*/*/ || code === 92/*\*/) { // `path` contains just a path separator, exit early to avoid // unnecessary work - ret.root = ret.dir = path[0]; + ret.root = ret.dir = path; return ret; } From 25d96010c62919b12a2101161f5d5dbd28f10a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 24 Jul 2017 16:20:30 +0200 Subject: [PATCH 4/5] add tests --- test/parallel/test-path-parse-format.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 5d78a6f52643ad..129500998ae137 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -32,6 +32,8 @@ const winPaths = [ 'file', '.\\file', 'C:\\', + 'C:', + '\\', '', // unc From fdbffaf58e0896b4eac044b197ae80582a80d4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 24 Jul 2017 17:03:20 +0200 Subject: [PATCH 5/5] add more detailed tests --- test/parallel/test-path-parse-format.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 129500998ae137..0f70d8ae4e7a23 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -44,7 +44,9 @@ const winPaths = [ ]; const winSpecialCaseParseTests = [ - ['/foo/bar', { root: '/' }] + ['/foo/bar', { root: '/' }], + ['C:', { root: 'C:', dir: 'C:', base: '' }], + ['C:\\', { root: 'C:\\', dir: 'C:\\', base: '' }] ]; const winSpecialCaseFormatTests = [