Skip to content

Commit 607fde1

Browse files
committed
wip
1 parent b656e15 commit 607fde1

File tree

1 file changed

+40
-52
lines changed

1 file changed

+40
-52
lines changed

src/librustdoc/html/render/search_index.rs

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,26 +1241,6 @@ impl<'de> Deserialize<'de> for SerializedOptional32 {
12411241
}
12421242
}
12431243

1244-
trait VecExt<T> {
1245-
fn get_mut_ensured(&mut self, index: usize) -> &mut T
1246-
where
1247-
T: Default + Clone;
1248-
}
1249-
1250-
impl<T> VecExt<T> for Vec<T> {
1251-
fn get_mut_ensured(&mut self, index: usize) -> &mut T
1252-
where
1253-
T: Default,
1254-
{
1255-
if self.len() <= index {
1256-
&mut self[index]
1257-
} else {
1258-
self.resize_with(index, T::default);
1259-
self.push_mut(T::default())
1260-
}
1261-
}
1262-
}
1263-
12641244
/// Builds the search index from the collected metadata
12651245
pub(crate) fn build_index(
12661246
krate: &clean::Crate,
@@ -1891,41 +1871,49 @@ pub(crate) fn build_index(
18911871
// unoccupied size.
18921872
if item.ty.is_fn_like() { 0 } else { 16 };
18931873
serialized_index.function_data[new_entry_id] = Some(search_type.clone());
1894-
for index in used_in_function_inputs {
1895-
let postings = if index >= 0 {
1896-
assert!(serialized_index.path_data[index as usize].is_some());
1897-
&mut serialized_index.type_data[index as usize]
1898-
.as_mut()
1899-
.unwrap()
1900-
.inverted_function_inputs_index
1901-
} else {
1902-
let generic_id = usize::try_from(-index).unwrap() - 1;
1903-
serialized_index.generic_inverted_index.get_mut_ensured(generic_id)
1904-
};
1905-
let posting = postings.get_mut_ensured(search_type_size);
1906-
if posting.last() != Some(&(new_entry_id as u32)) {
1907-
posting.push(new_entry_id as u32);
1908-
}
1909-
}
1910-
for index in used_in_function_output {
1911-
let postings = if index >= 0 {
1912-
assert!(serialized_index.path_data[index as usize].is_some());
1913-
&mut serialized_index.type_data[index as usize]
1914-
.as_mut()
1915-
.unwrap()
1916-
.inverted_function_output_index
1917-
} else {
1918-
let generic_id = usize::try_from(-index).unwrap() - 1;
1919-
for _ in serialized_index.generic_inverted_index.len()..=generic_id {
1920-
serialized_index.generic_inverted_index.push(Vec::new());
1874+
fn process_used_in_function(
1875+
serialized_index: &mut SerializedSearchIndex,
1876+
search_type_size: usize,
1877+
new_entry_id: usize,
1878+
get_index: impl Fn(&mut TypeData) -> &mut Vec<Vec<u32>>,
1879+
used_in_function: BTreeSet<isize>,
1880+
) {
1881+
for index in used_in_function {
1882+
let postings = if index >= 0 {
1883+
assert!(serialized_index.path_data[index as usize].is_some());
1884+
get_index(serialized_index.type_data[index as usize].as_mut().unwrap())
1885+
} else {
1886+
let generic_id = usize::try_from(-index).unwrap() - 1;
1887+
if generic_id >= serialized_index.generic_inverted_index.len() {
1888+
serialized_index
1889+
.generic_inverted_index
1890+
.resize(generic_id + 1, Vec::new());
1891+
}
1892+
&mut serialized_index.generic_inverted_index[generic_id]
1893+
};
1894+
if search_type_size >= postings.len() {
1895+
postings.resize(search_type_size + 1, Vec::new());
1896+
}
1897+
let posting = &mut postings[search_type_size];
1898+
if posting.last() != Some(&(new_entry_id as u32)) {
1899+
posting.push(new_entry_id as u32);
19211900
}
1922-
&mut serialized_index.generic_inverted_index[generic_id]
1923-
};
1924-
let posting = postings.get_mut_ensured(search_type_size);
1925-
if posting.last() != Some(&(new_entry_id as u32)) {
1926-
posting.push(new_entry_id as u32);
19271901
}
19281902
}
1903+
process_used_in_function(
1904+
&mut serialized_index,
1905+
search_type_size,
1906+
new_entry_id,
1907+
|type_data| &mut type_data.inverted_function_inputs_index,
1908+
used_in_function_inputs,
1909+
);
1910+
process_used_in_function(
1911+
&mut serialized_index,
1912+
search_type_size,
1913+
new_entry_id,
1914+
|type_data| &mut type_data.inverted_function_output_index,
1915+
used_in_function_output,
1916+
);
19291917
}
19301918
}
19311919

0 commit comments

Comments
 (0)