From 3f70bfa79cdd94a60e6ed17f7d7c46aab3df1414 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Mar 2021 23:52:46 -0700 Subject: [PATCH] Eagerly generate the underscore-less name to search on Basically, it doesn't make sense to generate those things every time you search. That generates a bunch of stuff for the GC to clean up, when, if the user wanted to do another search, it would just need to re-do it again. --- src/librustdoc/html/static/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7254f5f465c..6302c357c8f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1303,11 +1303,11 @@ function defocusSearchBar() { if (searchWords[j].indexOf(split[i]) > -1 || searchWords[j].indexOf(val) > -1 || - searchWords[j].replace(/_/g, "").indexOf(val) > -1) + ty.nameWithoutUnderscores.indexOf(val) > -1) { // filter type: ... queries if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) { - index = searchWords[j].replace(/_/g, "").indexOf(val); + index = ty.nameWithoutUnderscores.indexOf(val); } } if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { @@ -1860,6 +1860,7 @@ function defocusSearchBar() { parent: undefined, type: null, id: "", + nameWithoutUnderscores: crate.replace(/_/g, ""), }; crateRow.id = generateId(crateRow); searchIndex.push(crateRow); @@ -1909,6 +1910,7 @@ function defocusSearchBar() { parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: itemFunctionSearchTypes[i], id: "", + nameWithoutUnderscores: itemNames[i].replace(/_/g, ""), }; row.id = generateId(row); searchIndex.push(row);