From d15bfc04cde2bbfb2ce534639255dfcdab3cfcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Sun, 20 May 2012 22:26:29 +0300 Subject: [PATCH] path: small speed improvements --- lib/path.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/path.js b/lib/path.js index 438b05d8ef6..88c2df8cd71 100644 --- a/lib/path.js +++ b/lib/path.js @@ -33,7 +33,7 @@ function normalizeArray(parts, allowAboveRoot) { var up = 0; for (var i = parts.length - 1; i >= 0; i--) { var last = parts[i]; - if (last == '.') { + if (last === '.') { parts.splice(i, 1); } else if (last === '..') { parts.splice(i, 1); @@ -101,7 +101,7 @@ if (isWindows) { path = process.env['=' + resolvedDevice]; // Verify that a drive-local cwd was found and that it actually points // to our drive. If not, default to the drive's root. - if (!path || path.slice(0, 3).toLowerCase() !== + if (!path || path.substr(0, 3).toLowerCase() !== resolvedDevice.toLowerCase() + '\\') { path = resolvedDevice + '\\'; } @@ -191,14 +191,14 @@ if (isWindows) { return p && typeof p === 'string'; } - var paths = Array.prototype.slice.call(arguments, 0).filter(f); + var paths = Array.prototype.filter.call(arguments, f); var joined = paths.join('\\'); // Make sure that the joined path doesn't start with two slashes // - it will be mistaken for an unc path by normalize() - // unless the paths[0] also starts with two slashes if (/^[\\\/]{2}/.test(joined) && !/^[\\\/]{2}/.test(paths[0])) { - joined = joined.slice(1); + joined = joined.substr(1); } return exports.normalize(joined); @@ -307,7 +307,7 @@ if (isWindows) { // posix version exports.normalize = function(path) { var isAbsolute = path.charAt(0) === '/', - trailingSlash = path.slice(-1) === '/'; + trailingSlash = path.substr(-1) === '/'; // Normalize the path path = normalizeArray(path.split('/').filter(function(p) { @@ -393,7 +393,7 @@ exports.dirname = function(path) { if (dir) { // It has a dirname, strip trailing slash - dir = dir.substring(0, dir.length - 1); + dir = dir.substr(0, dir.length - 1); } return root + dir; @@ -434,11 +434,11 @@ if (isWindows) { var resolvedPath = exports.resolve(path); - if (resolvedPath.match(/^[a-zA-Z]\:\\/)) { + if (/^[a-zA-Z]\:\\/.test(resolvedPath)) { // path is local filesystem path, which needs to be converted // to long UNC path. return '\\\\?\\' + resolvedPath; - } else if (resolvedPath.match(/^\\\\[^?.]/)) { + } else if (/^\\\\[^?.]/.test(resolvedPath)) { // path is network UNC path, which needs to be converted // to long UNC path. return '\\\\?\\UNC\\' + resolvedPath.substring(2); @@ -450,4 +450,4 @@ if (isWindows) { exports._makeLong = function(path) { return path; }; -} +} \ No newline at end of file