path: improve posixSplitPath performance
authorEvan Lucas <evanlucas@me.com>
Wed, 23 Sep 2015 21:29:01 +0000 (16:29 -0500)
committerRod Vagg <rod@vagg.org>
Wed, 30 Sep 2015 06:02:13 +0000 (16:02 +1000)
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 <mscdex@mscdex.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
lib/path.js

index 4bcb2b3..0c9c656 100644 (file)
@@ -408,7 +408,9 @@ var posix = {};
 
 
 function posixSplitPath(filename) {
-  return splitPathRe.exec(filename).slice(1);
+  const out = splitPathRe.exec(filename);
+  out.shift();
+  return out;
 }