Skip to content

Commit

Permalink
Don't make unnecessary getcwd calls from path.resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and ry committed Feb 8, 2011
1 parent 6b50a9f commit 38d8cd6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/path.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) === '/';
}
Expand Down

0 comments on commit 38d8cd6

Please sign in to comment.