Skip to content

Commit 8127760

Browse files
notriddlecuviper
authored andcommitted
rustdoc-search: use the same ID for entry and path to same item
This decreases the size of the compiler-doc from 57MiB to 56MiB. (cherry picked from commit b9037f9)
1 parent b77c3b1 commit 8127760

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/librustdoc/html/render/search_index.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ impl SerializedSearchIndex {
239239
self.alias_pointers.push(alias_pointer);
240240
index
241241
}
242+
fn add_entry(&mut self, name: Symbol, entry_data: EntryData, desc: String) -> usize {
243+
let fqp = if let Some(module_path_index) = entry_data.module_path {
244+
let mut fqp = self.path_data[module_path_index].as_ref().unwrap().module_path.clone();
245+
fqp.push(Symbol::intern(&self.names[module_path_index]));
246+
fqp.push(name);
247+
fqp
248+
} else {
249+
vec![name]
250+
};
251+
if let Some(&other_path) = self.crate_paths_index.get(&(entry_data.ty, fqp))
252+
&& self.entry_data[other_path].is_none()
253+
&& self.descs[other_path].is_empty()
254+
{
255+
self.entry_data[other_path] = Some(entry_data);
256+
self.descs[other_path] = desc;
257+
other_path
258+
} else {
259+
self.push(name.as_str().to_string(), None, Some(entry_data), desc, None, None, None)
260+
}
261+
}
242262
fn push_path(&mut self, name: String, path_data: PathData) -> usize {
243263
self.push(name, Some(path_data), None, String::new(), None, None, None)
244264
}
@@ -1513,10 +1533,9 @@ pub(crate) fn build_index(
15131533
.as_ref()
15141534
.map(|path| serialized_index.get_id_by_module_path(path));
15151535

1516-
let new_entry_id = serialized_index.push(
1517-
item.name.as_str().to_string(),
1518-
None,
1519-
Some(EntryData {
1536+
let new_entry_id = serialized_index.add_entry(
1537+
item.name,
1538+
EntryData {
15201539
ty: item.ty,
15211540
parent: item.parent_idx,
15221541
module_path,
@@ -1535,11 +1554,8 @@ pub(crate) fn build_index(
15351554
None
15361555
},
15371556
krate: crate_idx,
1538-
}),
1557+
},
15391558
item.desc.to_string(),
1540-
None, // filled in after all the types have been indexed
1541-
None,
1542-
None,
15431559
);
15441560

15451561
// Aliases

0 commit comments

Comments
 (0)