diff options
| author | Michael Howell <michael@notriddle.com> | 2023-04-13 16:48:07 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-04-13 17:06:50 -0700 |
| commit | e34dc7f437732861be7eb875f6d7b2213b046560 (patch) | |
| tree | 490676936ccc872bc6571be3a9e6351fef914832 | |
| parent | 2179d9157ec0817ef0715f490382c6b95db355ee (diff) | |
| download | rust-e34dc7f437732861be7eb875f6d7b2213b046560.tar.gz rust-e34dc7f437732861be7eb875f6d7b2213b046560.zip | |
rustdoc-search: use ES6 `Map` for generic matching instead of `Object`
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index b0df5a28837..d19773f8d27 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1096,7 +1096,7 @@ function initSearch(rawSearchIndex) { // The names match, but we need to be sure that all generics kinda // match as well. if (elem.generics.length > 0 && row.generics.length >= elem.generics.length) { - const elems = Object.create(null); + const elems = new Map(); for (const entry of row.generics) { if (entry.name === "") { // Pure generic, needs to check into it. @@ -1106,39 +1106,30 @@ function initSearch(rawSearchIndex) { } continue; } - if (elems[entry.name] === undefined) { - elems[entry.name] = []; + let currentEntryElems; + if (elems.has(entry.name)) { + currentEntryElems = elems.get(entry.name); + } else { + currentEntryElems = []; + elems.set(entry.name, currentEntryElems); } - elems[entry.name].push(entry.ty); + currentEntryElems.push(entry.ty); } // We need to find the type that matches the most to remove it in order // to move forward. const handleGeneric = generic => { - let match = null; - if (elems[generic.name]) { - match = generic.name; - } else { - for (const elem_name in elems) { - if (!hasOwnPropertyRustdoc(elems, elem_name)) { - continue; - } - if (elem_name === generic) { - match = elem_name; - break; - } - } - } - if (match === null) { + if (!elems.has(generic.name)) { return false; } - const matchIdx = elems[match].findIndex(tmp_elem => + const matchElems = elems.get(generic.name); + const matchIdx = matchElems.findIndex(tmp_elem => typePassesFilter(generic.typeFilter, tmp_elem)); if (matchIdx === -1) { return false; } - elems[match].splice(matchIdx, 1); - if (elems[match].length === 0) { - delete elems[match]; + matchElems.splice(matchIdx, 1); + if (matchElems.length === 0) { + elems.delete(generic.name); } return true; }; |
