From 55d6b4961a7a24d75a8b03d3eb67f90a8f7e65d5 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 27 Jan 2019 15:27:28 +0100 Subject: [PATCH] path: refactor logic for to reduce code branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/path.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/path.js b/lib/path.js index ec27f280a59a61..d39f4f5d72dcf7 100644 --- a/lib/path.js +++ b/lib/path.js @@ -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; + } } }