Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-01-27 17:35:40 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-01 16:55:26 +0300
commite68b0d6fb333ae487bd04bd945342b2c63e4ead6 (patch)
treecfc477e41e7b0c32e19fe150d442bd760a878252 /lib/path.js
parente750e9583edfa6844c75b6c7bb0143e96506e280 (diff)
path: simplify code and remove obsolete checks
Either `end` is `-1` or `startPart` is not `0`. Therefore it's possible to move the conditions in a way that we eliminate a few code branches. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'lib/path.js')
-rw-r--r--lib/path.js59
1 files changed, 25 insertions, 34 deletions
diff --git a/lib/path.js b/lib/path.js
index d39f4f5d72d..b7b3788d84f 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -960,21 +960,20 @@ const win32 = {
}
}
- if (startDot === -1 ||
- end === -1 ||
- // We saw a non-dot character immediately before the dot
- preDotState === 0 ||
- // The (right-most) trimmed path component is exactly '..'
- (preDotState === 1 &&
- startDot === end - 1 &&
- startDot === startPart + 1)) {
- if (end !== -1) {
+ if (end !== -1) {
+ if (startDot === -1 ||
+ // We saw a non-dot character immediately before the dot
+ preDotState === 0 ||
+ // The (right-most) trimmed path component is exactly '..'
+ (preDotState === 1 &&
+ startDot === end - 1 &&
+ startDot === startPart + 1)) {
ret.base = ret.name = path.slice(startPart, end);
+ } else {
+ ret.name = path.slice(startPart, startDot);
+ ret.base = path.slice(startPart, end);
+ ret.ext = path.slice(startDot, end);
}
- } else {
- ret.name = path.slice(startPart, startDot);
- ret.base = path.slice(startPart, end);
- ret.ext = path.slice(startDot, end);
}
// If the directory is the root, use the entire root as the `dir` including
@@ -1380,29 +1379,21 @@ const posix = {
}
}
- if (startDot === -1 ||
- end === -1 ||
- // We saw a non-dot character immediately before the dot
- preDotState === 0 ||
- // The (right-most) trimmed path component is exactly '..'
- (preDotState === 1 &&
- startDot === end - 1 &&
- startDot === startPart + 1)) {
- if (end !== -1) {
- if (startPart === 0 && isAbsolute)
- ret.base = ret.name = path.slice(1, end);
- else
- ret.base = ret.name = path.slice(startPart, end);
- }
- } else {
- if (startPart === 0 && isAbsolute) {
- ret.name = path.slice(1, startDot);
- ret.base = path.slice(1, end);
+ if (end !== -1) {
+ const start = startPart === 0 && isAbsolute ? 1 : startPart;
+ if (startDot === -1 ||
+ // We saw a non-dot character immediately before the dot
+ preDotState === 0 ||
+ // The (right-most) trimmed path component is exactly '..'
+ (preDotState === 1 &&
+ startDot === end - 1 &&
+ startDot === startPart + 1)) {
+ ret.base = ret.name = path.slice(start, end);
} else {
- ret.name = path.slice(startPart, startDot);
- ret.base = path.slice(startPart, end);
+ ret.name = path.slice(start, startDot);
+ ret.base = path.slice(start, end);
+ ret.ext = path.slice(startDot, end);
}
- ret.ext = path.slice(startDot, end);
}
if (startPart > 0)