Skip to content

Commit 879d28d

Browse files
Move duplicates removal when generating results instead of when displaying them
1 parent 60f3bd7 commit 879d28d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,26 @@ window.initSearch = function(rawSearchIndex) {
152152
removeEmptyStringsFromArray(split);
153153

154154
function transformResults(results) {
155+
var duplicates = {};
155156
var out = [];
157+
156158
for (var i = 0, len = results.length; i < len; ++i) {
157-
if (results[i].id > -1) {
158-
var obj = searchIndex[results[i].id];
159-
obj.lev = results[i].lev;
159+
var result = results[i];
160+
161+
if (result.id > -1) {
162+
var obj = searchIndex[result.id];
163+
obj.lev = result.lev;
160164
var res = buildHrefAndPath(obj);
161165
obj.displayPath = pathSplitter(res[0]);
162166
obj.fullPath = obj.displayPath + obj.name;
163167
// To be sure than it some items aren't considered as duplicate.
164168
obj.fullPath += "|" + obj.ty;
169+
170+
if (duplicates[obj.fullPath]) {
171+
continue;
172+
}
173+
duplicates[obj.fullPath] = true;
174+
165175
obj.href = res[1];
166176
out.push(obj);
167177
if (out.length >= MAX_RESULTS) {
@@ -971,19 +981,11 @@ window.initSearch = function(rawSearchIndex) {
971981
}
972982

973983
var output = document.createElement("div");
974-
var duplicates = {};
975984
var length = 0;
976985
if (array.length > 0) {
977986
output.className = "search-results " + extraClass;
978987

979988
array.forEach(function(item) {
980-
if (item.is_alias !== true) {
981-
if (duplicates[item.fullPath]) {
982-
return;
983-
}
984-
duplicates[item.fullPath] = true;
985-
}
986-
987989
var name = item.name;
988990
var type = itemTypes[item.ty];
989991

0 commit comments

Comments
 (0)