diff options
| author | Michael Howell <michael@notriddle.com> | 2023-11-20 13:15:47 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-11-21 13:09:53 -0700 |
| commit | d82a08537aab25f3d1d43a30ea4b06422819bbfd (patch) | |
| tree | 9b16264b9a35c0bcdc5aa4754b824ee715db8cdb /src/librustdoc/html/static | |
| parent | 2f8d81f9dbac6b8df982199f69da04a4c8357227 (diff) | |
| download | rust-d82a08537aab25f3d1d43a30ea4b06422819bbfd.tar.gz rust-d82a08537aab25f3d1d43a30ea4b06422819bbfd.zip | |
rustdoc-search: clean up `checkPath`
This computes the same result with less code by computing many of the old checks at once: * It won't enter the loop if clength > length, because then the result of length - clength will be negative and the loop conditional will fail. * i + clength will never be greater than length, because it starts out as i = length - clength, implying that i + clength equals length, and it only goes down from there. * The aborted variable is replaced with control flow.
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 22dcb870143..495c28d91e8 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1840,26 +1840,16 @@ function initSearch(rawSearchIndex) { const length = path.length; const clength = contains.length; - if (clength > length) { - return maxEditDistance + 1; - } - for (let i = 0; i < length; ++i) { - if (i + clength > length) { - break; - } + pathiter: for (let i = length - clength; i >= 0; i -= 1) { let dist_total = 0; - let aborted = false; for (let x = 0; x < clength; ++x) { const dist = editDistance(path[i + x], contains[x], maxEditDistance); if (dist > maxEditDistance) { - aborted = true; - break; + continue pathiter; } dist_total += dist; } - if (!aborted) { - ret_dist = Math.min(ret_dist, Math.round(dist_total / clength)); - } + ret_dist = Math.min(ret_dist, Math.round(dist_total / clength)); } return ret_dist; } |
