diff options
author | Bert Belder <bertbelder@gmail.com> | 2011-02-08 22:56:03 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-02-08 14:30:24 -0800 |
commit | 38d8cd60ea168d28349e041dc0f2a0bf853c2497 (patch) | |
tree | ea40f25b99e8a67e4b3cf76ef687995966af93d7 /lib/path.js | |
parent | 6b50a9f5f4a7d0aea82c2b1f8b2b88d5568be4e1 (diff) | |
download | android-node-v8-38d8cd60ea168d28349e041dc0f2a0bf853c2497.tar.gz android-node-v8-38d8cd60ea168d28349e041dc0f2a0bf853c2497.tar.bz2 android-node-v8-38d8cd60ea168d28349e041dc0f2a0bf853c2497.zip |
Don't make unnecessary getcwd calls from path.resolve
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/path.js b/lib/path.js index 3bfcb9637c..641e21e4c4 100644 --- a/lib/path.js +++ b/lib/path.js @@ -47,16 +47,14 @@ if (isWindows) { // path.resolve([from ...], to) // windows version exports.resolve = function() { - // Prepend cwd to provided paths - var paths = [process.cwd()].concat( - Array.prototype.slice.call(arguments, 0)); - var resolvedDevice = '', resolvedTail = '', resolvedAbsolute = false; - for (var i = paths.length; i >= 0; i--) { - var path = paths[i]; + for (var i = arguments.length; i >= -1; i--) { + var path = (i >= 0) + ? arguments[i] + : process.cwd(); // Skip empty and invalid entries if (typeof path !== 'string' || !path) { @@ -177,19 +175,19 @@ if (isWindows) { // path.resolve([from ...], to) // posix version exports.resolve = function() { - // Prepend cwd to provided paths - var paths = [process.cwd()].concat( - Array.prototype.slice.call(arguments, 0)); - var resolvedPath = '', resolvedAbsolute = false; - for (var i = paths.length; i >= 0 && !resolvedAbsolute; i--) { - var path = paths[i]; + for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) + ? arguments[i] + : process.cwd(); + // Skip empty and invalid entries if (typeof path !== 'string' || !path) { continue; } + resolvedPath = path + '/' + resolvedPath; resolvedAbsolute = path.charAt(0) === '/'; } |