Skip to content

Commit e34dc7f

Browse files
committed
rustdoc-search: use ES6 Map for generic matching instead of Object
1 parent 2179d91 commit e34dc7f

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ function initSearch(rawSearchIndex) {
10961096
// The names match, but we need to be sure that all generics kinda
10971097
// match as well.
10981098
if (elem.generics.length > 0 && row.generics.length >= elem.generics.length) {
1099-
const elems = Object.create(null);
1099+
const elems = new Map();
11001100
for (const entry of row.generics) {
11011101
if (entry.name === "") {
11021102
// Pure generic, needs to check into it.
@@ -1106,39 +1106,30 @@ function initSearch(rawSearchIndex) {
11061106
}
11071107
continue;
11081108
}
1109-
if (elems[entry.name] === undefined) {
1110-
elems[entry.name] = [];
1109+
let currentEntryElems;
1110+
if (elems.has(entry.name)) {
1111+
currentEntryElems = elems.get(entry.name);
1112+
} else {
1113+
currentEntryElems = [];
1114+
elems.set(entry.name, currentEntryElems);
11111115
}
1112-
elems[entry.name].push(entry.ty);
1116+
currentEntryElems.push(entry.ty);
11131117
}
11141118
// We need to find the type that matches the most to remove it in order
11151119
// to move forward.
11161120
const handleGeneric = generic => {
1117-
let match = null;
1118-
if (elems[generic.name]) {
1119-
match = generic.name;
1120-
} else {
1121-
for (const elem_name in elems) {
1122-
if (!hasOwnPropertyRustdoc(elems, elem_name)) {
1123-
continue;
1124-
}
1125-
if (elem_name === generic) {
1126-
match = elem_name;
1127-
break;
1128-
}
1129-
}
1130-
}
1131-
if (match === null) {
1121+
if (!elems.has(generic.name)) {
11321122
return false;
11331123
}
1134-
const matchIdx = elems[match].findIndex(tmp_elem =>
1124+
const matchElems = elems.get(generic.name);
1125+
const matchIdx = matchElems.findIndex(tmp_elem =>
11351126
typePassesFilter(generic.typeFilter, tmp_elem));
11361127
if (matchIdx === -1) {
11371128
return false;
11381129
}
1139-
elems[match].splice(matchIdx, 1);
1140-
if (elems[match].length === 0) {
1141-
delete elems[match];
1130+
matchElems.splice(matchIdx, 1);
1131+
if (matchElems.length === 0) {
1132+
elems.delete(generic.name);
11421133
}
11431134
return true;
11441135
};

0 commit comments

Comments
 (0)