path: refactor logic for to reduce code branches

This refactoring makes sure some code branches will not be hit if
they do not have to be reached.

PR-URL: https://github.com/nodejs/node/pull/25278
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Ruben Bridgewater 2019-01-27 15:27:28 +01:00
parent f59fdd9d65
commit e750e9583e
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -224,23 +224,25 @@ const win32 = {
isAbsolute = true;
}
if (device.length > 0 &&
resolvedDevice.length > 0 &&
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
// This path points to another device so it is not applicable
continue;
if (device.length > 0) {
if (resolvedDevice.length > 0) {
if (device.toLowerCase() !== resolvedDevice.toLowerCase())
// This path points to another device so it is not applicable
continue;
} else {
resolvedDevice = device;
}
}
if (resolvedDevice.length === 0 && device.length > 0) {
resolvedDevice = device;
}
if (!resolvedAbsolute) {
resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
if (resolvedAbsolute) {
if (resolvedDevice.length > 0)
break;
} else {
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
resolvedAbsolute = isAbsolute;
}
if (resolvedDevice.length > 0 && resolvedAbsolute) {
break;
if (isAbsolute && resolvedDevice.length > 0) {
break;
}
}
}