From 37d27486fce50bd82b6b5095af880d435ed308f8 Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 2 Aug 2019 21:04:56 -0400 Subject: [PATCH] path: improve normalization performance PR-URL: https://github.com/nodejs/node/pull/28948 Reviewed-By: Yongsheng Zhang Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: Gus Caplan --- lib/path.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/path.js b/lib/path.js index e278c891482..884da4cd8e6 100644 --- a/lib/path.js +++ b/lib/path.js @@ -95,7 +95,10 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { lastSegmentLength = 2; } } else { - res += (res.length > 0 ? separator : '') + path.slice(lastSlash + 1, i); + if (res.length > 0) + res += `${separator}${path.slice(lastSlash + 1, i)}`; + else + res = path.slice(lastSlash + 1, i); lastSegmentLength = i - lastSlash - 1; } lastSlash = i;