Skip to content

Commit d244f98

Browse files
committed
rustdoc-search: sort typ-based inverted indexes by length
This gives us incremental search results back for types, so type-based search feels faster even for queries with lots of matches.
1 parent ed454bf commit d244f98

File tree

6 files changed

+471
-199
lines changed

6 files changed

+471
-199
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ struct RenderType {
151151
}
152152

153153
impl RenderType {
154+
fn size(&self) -> usize {
155+
let mut size = 1;
156+
if let Some(generics) = &self.generics {
157+
size += generics.iter().map(RenderType::size).sum::<usize>();
158+
}
159+
if let Some(bindings) = &self.bindings {
160+
for (_, constraints) in bindings.iter() {
161+
size += 1;
162+
size += constraints.iter().map(RenderType::size).sum::<usize>();
163+
}
164+
}
165+
size
166+
}
154167
// Types are rendered as lists of lists, because that's pretty compact.
155168
// The contents of the lists are always integers in self-terminating hex
156169
// form, handled by `RenderTypeId::write_to_string`, so no commas are
@@ -296,6 +309,15 @@ pub(crate) struct IndexItemFunctionType {
296309
}
297310

298311
impl IndexItemFunctionType {
312+
fn size(&self) -> usize {
313+
self.inputs.iter().map(RenderType::size).sum::<usize>()
314+
+ self.output.iter().map(RenderType::size).sum::<usize>()
315+
+ self
316+
.where_clause
317+
.iter()
318+
.map(|constraints| constraints.iter().map(RenderType::size).sum::<usize>())
319+
.sum::<usize>()
320+
}
299321
fn read_from_string_without_param_names(string: &[u8]) -> (IndexItemFunctionType, usize) {
300322
let mut i = 0;
301323
if string[i] == b'`' {

0 commit comments

Comments
 (0)