Don't make unnecessary getcwd calls from path.resolve
This commit is contained in:
parent
6b50a9f5f4
commit
38d8cd60ea
22
lib/path.js
22
lib/path.js
@ -47,16 +47,14 @@ if (isWindows) {
|
|||||||
// path.resolve([from ...], to)
|
// path.resolve([from ...], to)
|
||||||
// windows version
|
// windows version
|
||||||
exports.resolve = function() {
|
exports.resolve = function() {
|
||||||
// Prepend cwd to provided paths
|
|
||||||
var paths = [process.cwd()].concat(
|
|
||||||
Array.prototype.slice.call(arguments, 0));
|
|
||||||
|
|
||||||
var resolvedDevice = '',
|
var resolvedDevice = '',
|
||||||
resolvedTail = '',
|
resolvedTail = '',
|
||||||
resolvedAbsolute = false;
|
resolvedAbsolute = false;
|
||||||
|
|
||||||
for (var i = paths.length; i >= 0; i--) {
|
for (var i = arguments.length; i >= -1; i--) {
|
||||||
var path = paths[i];
|
var path = (i >= 0)
|
||||||
|
? arguments[i]
|
||||||
|
: process.cwd();
|
||||||
|
|
||||||
// Skip empty and invalid entries
|
// Skip empty and invalid entries
|
||||||
if (typeof path !== 'string' || !path) {
|
if (typeof path !== 'string' || !path) {
|
||||||
@ -177,19 +175,19 @@ if (isWindows) {
|
|||||||
// path.resolve([from ...], to)
|
// path.resolve([from ...], to)
|
||||||
// posix version
|
// posix version
|
||||||
exports.resolve = function() {
|
exports.resolve = function() {
|
||||||
// Prepend cwd to provided paths
|
|
||||||
var paths = [process.cwd()].concat(
|
|
||||||
Array.prototype.slice.call(arguments, 0));
|
|
||||||
|
|
||||||
var resolvedPath = '',
|
var resolvedPath = '',
|
||||||
resolvedAbsolute = false;
|
resolvedAbsolute = false;
|
||||||
|
|
||||||
for (var i = paths.length; i >= 0 && !resolvedAbsolute; i--) {
|
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
||||||
var path = paths[i];
|
var path = (i >= 0)
|
||||||
|
? arguments[i]
|
||||||
|
: process.cwd();
|
||||||
|
|
||||||
// Skip empty and invalid entries
|
// Skip empty and invalid entries
|
||||||
if (typeof path !== 'string' || !path) {
|
if (typeof path !== 'string' || !path) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvedPath = path + '/' + resolvedPath;
|
resolvedPath = path + '/' + resolvedPath;
|
||||||
resolvedAbsolute = path.charAt(0) === '/';
|
resolvedAbsolute = path.charAt(0) === '/';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user