Skip to content

Commit

Permalink
Avoid generating new strings for names that have no undescores
Browse files Browse the repository at this point in the history
This should have negligible effect on time, but it cuts about 1MiB
off of resident memory usage.
  • Loading branch information
notriddle committed Mar 14, 2021
1 parent d92f840 commit 0bfd142
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1864,7 +1867,7 @@ function defocusSearchBar() {
parent: undefined,
type: null,
id: "",
nameWithoutUnderscores: crate.replace(/_/g, ""),
nameWithoutUnderscores: nameWithoutUnderscores,
};
crateRow.id = generateId(crateRow);
searchIndex.push(crateRow);
Expand Down Expand Up @@ -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],
Expand All @@ -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);
Expand Down

0 comments on commit 0bfd142

Please sign in to comment.