From 5fe3b8703482a132c628c102f3c188657668080e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Mar 2021 22:59:16 -0700 Subject: Get rid of the garbage produced by getObjectFromId There is no reason for this function to return an object, since it is always used for getting at the name anyhow. It's used in the inner loop for some popular functions, so we want to avoid allocating in it. --- src/librustdoc/html/static/main.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index ac2da5f779b..24170837e3a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -833,11 +833,11 @@ function defocusSearchBar() { }; } - function getObjectFromId(id) { + function getObjectNameFromId(id) { if (typeof id === "number") { - return searchIndex[id]; + return searchIndex[id].name; } - return {'name': id}; + return id; } function checkGenerics(obj, val) { @@ -854,9 +854,9 @@ function defocusSearchBar() { var vlength = val.generics.length; for (var y = 0; y < vlength; ++y) { var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1}; - var firstGeneric = getObjectFromId(val.generics[y]).name; + var firstGeneric = getObjectNameFromId(val.generics[y]); for (var x = 0, elength = elems.length; x < elength; ++x) { - var tmp_lev = levenshtein(getObjectFromId(elems[x]).name, + var tmp_lev = levenshtein(getObjectNameFromId(elems[x]), firstGeneric); if (tmp_lev < lev.lev) { lev.lev = tmp_lev; @@ -892,10 +892,10 @@ function defocusSearchBar() { len = val.generics.length; for (y = 0; allFound === true && y < len; ++y) { allFound = false; - firstGeneric = getObjectFromId(val.generics[y]).name; + firstGeneric = getObjectNameFromId(val.generics[y]); e_len = elems.length; for (x = 0; allFound === false && x < e_len; ++x) { - allFound = getObjectFromId(elems[x]).name === firstGeneric; + allFound = getObjectNameFromId(elems[x]) === firstGeneric; } if (allFound === true) { elems.splice(x - 1, 1); -- cgit 1.4.1-3-g733a5 From d7971e587c948ce943d962073ea3caa7f6830c1d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Mar 2021 23:23:42 -0700 Subject: In checkGenerics and checkType, don't use Array.prototype.splice so much Every time splice() is called, another temporary object is created. This version, which uses plain objects as a sort of Hash Bag, should only produce one temporary object each time it's called. --- src/librustdoc/html/static/main.js | 94 +++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 37 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 24170837e3a..7254f5f465c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -846,26 +846,38 @@ function defocusSearchBar() { if (val.generics.length > 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { - var elems = obj[GENERICS_DATA].slice(0); + var elems = {}; + var elength = object[GENERICS_DATA].length; + for (var x = 0; x < elength; ++x) { + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; + } var total = 0; var done = 0; // We need to find the type that matches the most to remove it in order // to move forward. var vlength = val.generics.length; - for (var y = 0; y < vlength; ++y) { - var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1}; - var firstGeneric = getObjectNameFromId(val.generics[y]); - for (var x = 0, elength = elems.length; x < elength; ++x) { - var tmp_lev = levenshtein(getObjectNameFromId(elems[x]), - firstGeneric); - if (tmp_lev < lev.lev) { - lev.lev = tmp_lev; - lev.pos = x; + for (var x = 0; x < vlength; ++x) { + var lev = MAX_LEV_DISTANCE + 1; + var firstGeneric = getObjectNameFromId(val.generics[x]); + var match = undefined; + if (elems[firstGeneric]) { + match = firstGeneric; + lev = 0; + } else { + for (var elem_name in elems) { + var tmp_lev = levenshtein(elem_name, firstGeneric); + if (tmp_lev < lev) { + lev = tmp_lev; + match = elem_name; + } } } - if (lev.pos !== -1) { - elems.splice(lev.pos, 1); - total += lev.lev; + if (match !== undefined) { + elems[match] -= 1; + if (elems[match] == 0) { + delete elems[match]; + } + total += lev; done += 1; } else { return MAX_LEV_DISTANCE + 1; @@ -880,25 +892,27 @@ function defocusSearchBar() { // Check for type name and type generics (if any). function checkType(obj, val, literalSearch) { var lev_distance = MAX_LEV_DISTANCE + 1; - var len, x, y, e_len, firstGeneric; + var len, x, firstGeneric; if (obj[NAME] === val.name) { if (literalSearch === true) { if (val.generics && val.generics.length !== 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { - var elems = obj[GENERICS_DATA].slice(0); - var allFound = true; + var elems = {}; + len = obj[GENERICS_DATA].length; + for (x = 0; x < len; ++x) { + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; + } + var allFound = true; len = val.generics.length; - for (y = 0; allFound === true && y < len; ++y) { - allFound = false; - firstGeneric = getObjectNameFromId(val.generics[y]); - e_len = elems.length; - for (x = 0; allFound === false && x < e_len; ++x) { - allFound = getObjectNameFromId(elems[x]) === firstGeneric; - } - if (allFound === true) { - elems.splice(x - 1, 1); + for (x = 0; x < len; ++x) { + firstGeneric = getObjectNameFromId(val.generics[x]); + if (elems[firstGeneric]) { + elems[firstGeneric] -= 1; + } else { + allFound = false; + break; } } if (allFound === true) { @@ -1066,13 +1080,6 @@ function defocusSearchBar() { return false; } - function generateId(ty) { - if (ty.parent && ty.parent.name) { - return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name; - } - return itemTypes[ty.ty] + ty.path + ty.name; - } - function createAliasFromItem(item) { return { crate: item.crate, @@ -1158,7 +1165,7 @@ function defocusSearchBar() { in_args = findArg(searchIndex[i], val, true, typeFilter); returned = checkReturned(searchIndex[i], val, true, typeFilter); ty = searchIndex[i]; - fullId = generateId(ty); + fullId = ty.id; if (searchWords[i] === val.name && typePassesFilter(typeFilter, searchIndex[i].ty) @@ -1208,7 +1215,7 @@ function defocusSearchBar() { if (!type) { continue; } - fullId = generateId(ty); + fullId = ty.id; returned = checkReturned(ty, output, true, NO_TYPE_FILTER); if (output.name === "*" || returned === true) { @@ -1292,7 +1299,7 @@ function defocusSearchBar() { var index = -1; // we want lev results to go lower than others lev = MAX_LEV_DISTANCE + 1; - fullId = generateId(ty); + fullId = ty.id; if (searchWords[j].indexOf(split[i]) > -1 || searchWords[j].indexOf(val) > -1 || @@ -1825,6 +1832,13 @@ function defocusSearchBar() { showResults(execSearch(query, index, filterCrates)); } + function generateId(ty) { + if (ty.parent && ty.parent.name) { + return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name; + } + return itemTypes[ty.ty] + ty.path + ty.name; + } + function buildIndex(rawSearchIndex) { searchIndex = []; var searchWords = []; @@ -1837,14 +1851,18 @@ function defocusSearchBar() { var crateSize = 0; searchWords.push(crate); - searchIndex.push({ + var crateRow = { crate: crate, ty: 1, // == ExternCrate name: crate, path: "", desc: rawSearchIndex[crate].doc, + parent: undefined, type: null, - }); + id: "", + }; + crateRow.id = generateId(crateRow); + searchIndex.push(crateRow); currentIndex += 1; // an array of (Number) item types @@ -1890,7 +1908,9 @@ function defocusSearchBar() { desc: itemDescs[i], parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: itemFunctionSearchTypes[i], + id: "", }; + row.id = generateId(row); searchIndex.push(row); if (typeof row.name === "string") { var word = row.name.toLowerCase(); -- cgit 1.4.1-3-g733a5 From 3f70bfa79cdd94a60e6ed17f7d7c46aab3df1414 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Mar 2021 23:52:46 -0700 Subject: 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(-) (limited to 'src/librustdoc/html/static') 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); -- cgit 1.4.1-3-g733a5 From b76a3d3592f1b7c495501a892f537635a7a313c3 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 09:32:40 -0700 Subject: Update src/librustdoc/html/static/main.js Co-authored-by: Guillaume Gomez --- src/librustdoc/html/static/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6302c357c8f..6ec97f2e924 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -856,7 +856,7 @@ function defocusSearchBar() { // We need to find the type that matches the most to remove it in order // to move forward. var vlength = val.generics.length; - for (var x = 0; x < vlength; ++x) { + for (x = 0; x < vlength; ++x) { var lev = MAX_LEV_DISTANCE + 1; var firstGeneric = getObjectNameFromId(val.generics[x]); var match = undefined; -- cgit 1.4.1-3-g733a5 From ca04ce364552b58ce8cb5dabcbec6ca88cb1b1e0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 09:34:37 -0700 Subject: Use null instead of undefined here --- src/librustdoc/html/static/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6ec97f2e924..38f244ba89f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -859,7 +859,7 @@ function defocusSearchBar() { for (x = 0; x < vlength; ++x) { var lev = MAX_LEV_DISTANCE + 1; var firstGeneric = getObjectNameFromId(val.generics[x]); - var match = undefined; + var match = null; if (elems[firstGeneric]) { match = firstGeneric; lev = 0; @@ -872,7 +872,7 @@ function defocusSearchBar() { } } } - if (match !== undefined) { + if (match !== null) { elems[match] -= 1; if (elems[match] == 0) { delete elems[match]; -- cgit 1.4.1-3-g733a5 From b7d14b1b4d75f6f7ea1cd1801c933f0d4f76c222 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 09:54:19 -0700 Subject: Fix jslint warnings --- src/librustdoc/html/static/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 38f244ba89f..d444bc2f257 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -843,6 +843,7 @@ function defocusSearchBar() { function checkGenerics(obj, val) { // The names match, but we need to be sure that all generics kinda // match as well. + var tmp_lev, elem_name; if (val.generics.length > 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { @@ -864,8 +865,8 @@ function defocusSearchBar() { match = firstGeneric; lev = 0; } else { - for (var elem_name in elems) { - var tmp_lev = levenshtein(elem_name, firstGeneric); + for (elem_name in elems) { + tmp_lev = levenshtein(elem_name, firstGeneric); if (tmp_lev < lev) { lev = tmp_lev; match = elem_name; -- cgit 1.4.1-3-g733a5 From 7834aeb95c5ddebdfadcf5cbc035912c117cc106 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 10:12:17 -0700 Subject: Add comments regarding object shapes in buildIndex --- src/librustdoc/html/static/main.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d444bc2f257..72aa985dc59 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1852,6 +1852,9 @@ function defocusSearchBar() { var crateSize = 0; searchWords.push(crate); + // This object should have exactly the same set of fields as the "row" + // object defined below. Your JavaScript runtime will thank you. + // https://mathiasbynens.be/notes/shapes-ics var crateRow = { crate: crate, ty: 1, // == ExternCrate @@ -1902,6 +1905,8 @@ function defocusSearchBar() { len = itemTypes.length; var lastPath = ""; for (i = 0; i < len; ++i) { + // This object should have exactly the same set of fields as the "crateRow" + // object defined above. var row = { crate: crate, ty: itemTypes[i], -- cgit 1.4.1-3-g733a5 From 26f85cc1729cc7e324ae7675fb8e1f03014a062f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 10:28:36 -0700 Subject: Avoid potential collisions with `constructor` and the search query --- src/librustdoc/html/static/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 72aa985dc59..b7ed355c2e7 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -847,7 +847,7 @@ function defocusSearchBar() { if (val.generics.length > 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { - var elems = {}; + var elems = Object.create(null); var elength = object[GENERICS_DATA].length; for (var x = 0; x < elength; ++x) { elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; @@ -899,7 +899,7 @@ function defocusSearchBar() { if (val.generics && val.generics.length !== 0) { if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length >= val.generics.length) { - var elems = {}; + var elems = Object.create(null); len = obj[GENERICS_DATA].length; for (x = 0; x < len; ++x) { elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; -- cgit 1.4.1-3-g733a5 From d92f8405ce8cb6fd3b2967d0624902c8260a890f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Mar 2021 10:29:21 -0700 Subject: Remove tab character --- src/librustdoc/html/static/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index b7ed355c2e7..d6d0f98fa7b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1905,8 +1905,8 @@ function defocusSearchBar() { len = itemTypes.length; var lastPath = ""; for (i = 0; i < len; ++i) { - // This object should have exactly the same set of fields as the "crateRow" - // object defined above. + // This object should have exactly the same set of fields as the "crateRow" + // object defined above. var row = { crate: crate, ty: itemTypes[i], -- cgit 1.4.1-3-g733a5 From 0bfd1429266518d86d28c29f86c30bca063706f0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 14 Mar 2021 09:48:48 -0700 Subject: Avoid generating new strings for names that have no undescores This should have negligible effect on time, but it cuts about 1MiB off of resident memory usage. --- src/librustdoc/html/static/main.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d6d0f98fa7b..729a1297324 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1852,6 +1852,9 @@ function defocusSearchBar() { var crateSize = 0; searchWords.push(crate); + var nameWithoutUnderscores = crate.indexOf("_") === -1 + ? crate + : crate.replace(/_/g, ""); // This object should have exactly the same set of fields as the "row" // object defined below. Your JavaScript runtime will thank you. // https://mathiasbynens.be/notes/shapes-ics @@ -1864,7 +1867,7 @@ function defocusSearchBar() { parent: undefined, type: null, id: "", - nameWithoutUnderscores: crate.replace(/_/g, ""), + nameWithoutUnderscores: nameWithoutUnderscores, }; crateRow.id = generateId(crateRow); searchIndex.push(crateRow); @@ -1907,6 +1910,9 @@ function defocusSearchBar() { for (i = 0; i < len; ++i) { // This object should have exactly the same set of fields as the "crateRow" // object defined above. + var nameWithoutUnderscores = itemNames[i].indexOf("_") === -1 + ? itemNames[i] + : itemNames[i].replace(/_/g, ""); var row = { crate: crate, ty: itemTypes[i], @@ -1916,7 +1922,7 @@ function defocusSearchBar() { parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: itemFunctionSearchTypes[i], id: "", - nameWithoutUnderscores: itemNames[i].replace(/_/g, ""), + nameWithoutUnderscores: nameWithoutUnderscores, }; row.id = generateId(row); searchIndex.push(row); -- cgit 1.4.1-3-g733a5 From f57d71533eb6199b04f62bb54c8f19d655d3c824 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 14 Mar 2021 09:57:37 -0700 Subject: Use a number for row.id, instead of a string There's no reason for it to be a string, since it's only used for de-duplicating the results arrays anyhow. --- src/librustdoc/html/static/main.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 729a1297324..68a7ed9a905 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1833,18 +1833,12 @@ function defocusSearchBar() { showResults(execSearch(query, index, filterCrates)); } - function generateId(ty) { - if (ty.parent && ty.parent.name) { - return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name; - } - return itemTypes[ty.ty] + ty.path + ty.name; - } - function buildIndex(rawSearchIndex) { searchIndex = []; var searchWords = []; var i; var currentIndex = 0; + var id = 0; for (var crate in rawSearchIndex) { if (!hasOwnProperty(rawSearchIndex, crate)) { continue; } @@ -1866,10 +1860,10 @@ function defocusSearchBar() { desc: rawSearchIndex[crate].doc, parent: undefined, type: null, - id: "", + id: id, nameWithoutUnderscores: nameWithoutUnderscores, }; - crateRow.id = generateId(crateRow); + id += 1; searchIndex.push(crateRow); currentIndex += 1; @@ -1921,10 +1915,10 @@ function defocusSearchBar() { desc: itemDescs[i], parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: itemFunctionSearchTypes[i], - id: "", + id: id, nameWithoutUnderscores: nameWithoutUnderscores, }; - row.id = generateId(row); + id += 1; searchIndex.push(row); if (typeof row.name === "string") { var word = row.name.toLowerCase(); -- cgit 1.4.1-3-g733a5 From 8eba927a3e732ee3bf992ac31d587294f81e8c46 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 14 Mar 2021 14:43:10 -0700 Subject: Make nameWithoutUndescores lowercased This basically fixes a search bug introduced by earlier changes. --- src/librustdoc/html/static/main.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 68a7ed9a905..fe1791e4b07 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1304,11 +1304,11 @@ function defocusSearchBar() { if (searchWords[j].indexOf(split[i]) > -1 || searchWords[j].indexOf(val) > -1 || - ty.nameWithoutUnderscores.indexOf(val) > -1) + ty.normalizedName.indexOf(val) > -1) { // filter type: ... queries if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) { - index = ty.nameWithoutUnderscores.indexOf(val); + index = ty.normalizedName.indexOf(val); } } if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { @@ -1846,7 +1846,7 @@ function defocusSearchBar() { var crateSize = 0; searchWords.push(crate); - var nameWithoutUnderscores = crate.indexOf("_") === -1 + var normalizedName = crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""); // This object should have exactly the same set of fields as the "row" @@ -1861,7 +1861,7 @@ function defocusSearchBar() { parent: undefined, type: null, id: id, - nameWithoutUnderscores: nameWithoutUnderscores, + normalizedName: normalizedName, }; id += 1; searchIndex.push(crateRow); @@ -1904,9 +1904,16 @@ function defocusSearchBar() { for (i = 0; i < len; ++i) { // This object should have exactly the same set of fields as the "crateRow" // object defined above. - var nameWithoutUnderscores = itemNames[i].indexOf("_") === -1 - ? itemNames[i] - : itemNames[i].replace(/_/g, ""); + if (typeof itemNames[i] === "string") { + var word = itemNames[i].toLowerCase(); + searchWords.push(word); + } else { + var word = ""; + searchWords.push(""); + } + var normalizedName = word.indexOf("_") === -1 + ? word + : word.replace(/_/g, ""); var row = { crate: crate, ty: itemTypes[i], @@ -1916,16 +1923,10 @@ function defocusSearchBar() { parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: itemFunctionSearchTypes[i], id: id, - nameWithoutUnderscores: nameWithoutUnderscores, + normalizedName: normalizedName, }; id += 1; searchIndex.push(row); - if (typeof row.name === "string") { - var word = row.name.toLowerCase(); - searchWords.push(word); - } else { - searchWords.push(""); - } lastPath = row.path; crateSize += 1; } -- cgit 1.4.1-3-g733a5 From dcba95f43ee7b3d7a282f4d96f98d3a1deeafcd2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 15 Mar 2021 11:58:34 -0700 Subject: Declare `word` outside the loop, as recommended by eslint --- src/librustdoc/html/static/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index fe1791e4b07..0a63fc589ae 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1836,7 +1836,7 @@ function defocusSearchBar() { function buildIndex(rawSearchIndex) { searchIndex = []; var searchWords = []; - var i; + var i, word; var currentIndex = 0; var id = 0; @@ -1905,10 +1905,10 @@ function defocusSearchBar() { // This object should have exactly the same set of fields as the "crateRow" // object defined above. if (typeof itemNames[i] === "string") { - var word = itemNames[i].toLowerCase(); + word = itemNames[i].toLowerCase(); searchWords.push(word); } else { - var word = ""; + word = ""; searchWords.push(""); } var normalizedName = word.indexOf("_") === -1 -- cgit 1.4.1-3-g733a5