Skip to content

Commit 9dce3e8

Browse files
committed
rustdoc-search: add descriptive comment to space-saving hack
1 parent b9037f9 commit 9dce3e8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustdoc/html/render/search_index.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ impl SerializedSearchIndex {
241241
self.alias_pointers.push(alias_pointer);
242242
index
243243
}
244+
/// Add potential search result to the database and return the row ID.
245+
///
246+
/// The returned ID can be used to attach more data to the search result.
244247
fn add_entry(&mut self, name: Symbol, entry_data: EntryData, desc: String) -> usize {
245248
let fqp = if let Some(module_path_index) = entry_data.module_path {
246249
let mut fqp = self.path_data[module_path_index].as_ref().unwrap().module_path.clone();
@@ -250,6 +253,11 @@ impl SerializedSearchIndex {
250253
} else {
251254
vec![name]
252255
};
256+
// If a path with the same name already exists, but no entry does,
257+
// we can fill in the entry without having to allocate a new row ID.
258+
//
259+
// Because paths and entries both share the same index, using the same
260+
// ID saves space by making the tree smaller.
253261
if let Some(&other_path) = self.crate_paths_index.get(&(entry_data.ty, fqp))
254262
&& self.entry_data[other_path].is_none()
255263
&& self.descs[other_path].is_empty()

0 commit comments

Comments
 (0)