MCPcopy Index your code
hub / github.com/nodejs/node / comparePathsWorker

Function comparePathsWorker

test/fixtures/snapshot/typescript.js:8052–8086  ·  view source on GitHub ↗
(a, b, componentComparer)

Source from the content-addressed store, hash-verified

8050 // check path for these segments: '', '.'. '..'
8051 var relativePathSegmentRegExp = /(?:\/\/)|(?:^|\/)\.\.?(?:$|\/)/;
8052 function comparePathsWorker(a, b, componentComparer) {
8053 if (a === b)
8054 return 0 /* Comparison.EqualTo */;
8055 if (a === undefined)
8056 return -1 /* Comparison.LessThan */;
8057 if (b === undefined)
8058 return 1 /* Comparison.GreaterThan */;
8059 // NOTE: Performance optimization - shortcut if the root segments differ as there would be no
8060 // need to perform path reduction.
8061 var aRoot = a.substring(0, getRootLength(a));
8062 var bRoot = b.substring(0, getRootLength(b));
8063 var result = ts.compareStringsCaseInsensitive(aRoot, bRoot);
8064 if (result !== 0 /* Comparison.EqualTo */) {
8065 return result;
8066 }
8067 // NOTE: Performance optimization - shortcut if there are no relative path segments in
8068 // the non-root portion of the path
8069 var aRest = a.substring(aRoot.length);
8070 var bRest = b.substring(bRoot.length);
8071 if (!relativePathSegmentRegExp.test(aRest) && !relativePathSegmentRegExp.test(bRest)) {
8072 return componentComparer(aRest, bRest);
8073 }
8074 // The path contains a relative path segment. Normalize the paths and perform a slower component
8075 // by component comparison.
8076 var aComponents = reducePathComponents(getPathComponents(a));
8077 var bComponents = reducePathComponents(getPathComponents(b));
8078 var sharedLength = Math.min(aComponents.length, bComponents.length);
8079 for (var i = 1; i < sharedLength; i++) {
8080 var result_2 = componentComparer(aComponents[i], bComponents[i]);
8081 if (result_2 !== 0 /* Comparison.EqualTo */) {
8082 return result_2;
8083 }
8084 }
8085 return ts.compareValues(aComponents.length, bComponents.length);
8086 }
8087 /**
8088 * Performs a case-sensitive comparison of two paths. Path roots are always compared case-insensitively.
8089 */

Callers 3

comparePathsFunction · 0.85

Calls 5

getRootLengthFunction · 0.85
reducePathComponentsFunction · 0.85
getPathComponentsFunction · 0.85
testMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…