Skip to content

Commit 0bfd142

Browse files
committed
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.
1 parent d92f840 commit 0bfd142

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustdoc/html/static/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,9 @@ function defocusSearchBar() {
18521852
var crateSize = 0;
18531853

18541854
searchWords.push(crate);
1855+
var nameWithoutUnderscores = crate.indexOf("_") === -1
1856+
? crate
1857+
: crate.replace(/_/g, "");
18551858
// This object should have exactly the same set of fields as the "row"
18561859
// object defined below. Your JavaScript runtime will thank you.
18571860
// https://mathiasbynens.be/notes/shapes-ics
@@ -1864,7 +1867,7 @@ function defocusSearchBar() {
18641867
parent: undefined,
18651868
type: null,
18661869
id: "",
1867-
nameWithoutUnderscores: crate.replace(/_/g, ""),
1870+
nameWithoutUnderscores: nameWithoutUnderscores,
18681871
};
18691872
crateRow.id = generateId(crateRow);
18701873
searchIndex.push(crateRow);
@@ -1907,6 +1910,9 @@ function defocusSearchBar() {
19071910
for (i = 0; i < len; ++i) {
19081911
// This object should have exactly the same set of fields as the "crateRow"
19091912
// object defined above.
1913+
var nameWithoutUnderscores = itemNames[i].indexOf("_") === -1
1914+
? itemNames[i]
1915+
: itemNames[i].replace(/_/g, "");
19101916
var row = {
19111917
crate: crate,
19121918
ty: itemTypes[i],
@@ -1916,7 +1922,7 @@ function defocusSearchBar() {
19161922
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
19171923
type: itemFunctionSearchTypes[i],
19181924
id: "",
1919-
nameWithoutUnderscores: itemNames[i].replace(/_/g, ""),
1925+
nameWithoutUnderscores: nameWithoutUnderscores,
19201926
};
19211927
row.id = generateId(row);
19221928
searchIndex.push(row);

0 commit comments

Comments
 (0)