From 5fe3b8703482a132c628c102f3c188657668080e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Mar 2021 22:59:16 -0700 Subject: [PATCH] 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(-) 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);