Skip to content

Commit b9037f9

Browse files
committed
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.
1 parent 6f34f4e commit b9037f9

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
@@ -241,6 +241,26 @@ impl SerializedSearchIndex {
241241
self.alias_pointers.push(alias_pointer);
242242
index
243243
}
244+
fn add_entry(&mut self, name: Symbol, entry_data: EntryData, desc: String) -> usize {
245+
let fqp = if let Some(module_path_index) = entry_data.module_path {
246+
let mut fqp = self.path_data[module_path_index].as_ref().unwrap().module_path.clone();
247+
fqp.push(Symbol::intern(&self.names[module_path_index]));
248+
fqp.push(name);
249+
fqp
250+
} else {
251+
vec![name]
252+
};
253+
if let Some(&other_path) = self.crate_paths_index.get(&(entry_data.ty, fqp))
254+
&& self.entry_data[other_path].is_none()
255+
&& self.descs[other_path].is_empty()
256+
{
257+
self.entry_data[other_path] = Some(entry_data);
258+
self.descs[other_path] = desc;
259+
other_path
260+
} else {
261+
self.push(name.as_str().to_string(), None, Some(entry_data), desc, None, None, None)
262+
}
263+
}
244264
fn push_path(&mut self, name: String, path_data: PathData) -> usize {
245265
self.push(name, Some(path_data), None, String::new(), None, None, None)
246266
}
@@ -1516,10 +1536,9 @@ pub(crate) fn build_index(
15161536
.as_ref()
15171537
.map(|path| serialized_index.get_id_by_module_path(path));
15181538

1519-
let new_entry_id = serialized_index.push(
1520-
item.name.as_str().to_string(),
1521-
None,
1522-
Some(EntryData {
1539+
let new_entry_id = serialized_index.add_entry(
1540+
item.name,
1541+
EntryData {
15231542
ty: item.ty,
15241543
parent: item.parent_idx,
15251544
module_path,
@@ -1538,11 +1557,8 @@ pub(crate) fn build_index(
15381557
None
15391558
},
15401559
krate: crate_idx,
1541-
}),
1560+
},
15421561
item.desc.to_string(),
1543-
None, // filled in after all the types have been indexed
1544-
None,
1545-
None,
15461562
);
15471563

15481564
// Aliases

0 commit comments

Comments
 (0)