From ac2bce0b0c91ba9fc593d8c53c68b42d3c1e4954 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Wed, 23 Sep 2015 16:29:01 -0500 Subject: [PATCH] path: improve posixSplitPath performance Instead of slicing the first element off of the matches, shift and then return. This improves performance of the following path functions: - basename: 18-20% - extname: 60-70% - dirname: 18-20% - parse: 20-25% PR-URL: https://github.com/nodejs/node/pull/3034 Reviewed-By: Brian White Reviewed-By: Sakthipriyan Vairamani --- lib/path.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/path.js b/lib/path.js index 4bcb2b3672..0c9c656e66 100644 --- a/lib/path.js +++ b/lib/path.js @@ -408,7 +408,9 @@ var posix = {}; function posixSplitPath(filename) { - return splitPathRe.exec(filename).slice(1); + const out = splitPathRe.exec(filename); + out.shift(); + return out; }