From 0bfd1429266518d86d28c29f86c30bca063706f0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 14 Mar 2021 09:48:48 -0700 Subject: [PATCH] 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(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d6d0f98fa7b8..729a12973249 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);