mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-07 12:48:30 +00:00
Auto merge of #90813 - notriddle:notriddle/vec-extend, r=GuillaumeGomez
Use Vec extend and collect instead of repeatedly calling push
This commit is contained in:
commit
f31622a50b
@ -443,9 +443,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
|
|||||||
/// expands it.
|
/// expands it.
|
||||||
fn push(&mut self, row: PatStack<'p, 'tcx>) {
|
fn push(&mut self, row: PatStack<'p, 'tcx>) {
|
||||||
if !row.is_empty() && row.head().is_or_pat() {
|
if !row.is_empty() && row.head().is_or_pat() {
|
||||||
for row in row.expand_or_pat() {
|
self.patterns.extend(row.expand_or_pat());
|
||||||
self.patterns.push(row);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
self.patterns.push(row);
|
self.patterns.push(row);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ crate enum ExternalLocation {
|
|||||||
/// Builds the search index from the collected metadata
|
/// Builds the search index from the collected metadata
|
||||||
crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<'tcx>) -> String {
|
crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<'tcx>) -> String {
|
||||||
let mut defid_to_pathid = FxHashMap::default();
|
let mut defid_to_pathid = FxHashMap::default();
|
||||||
let mut crate_items = Vec::with_capacity(cache.search_index.len());
|
|
||||||
let mut crate_paths = vec![];
|
let mut crate_paths = vec![];
|
||||||
|
|
||||||
// Attach all orphan items to the type's definition if the type
|
// Attach all orphan items to the type's definition if the type
|
||||||
@ -77,10 +76,12 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
|||||||
|
|
||||||
// Reduce `DefId` in paths into smaller sequential numbers,
|
// Reduce `DefId` in paths into smaller sequential numbers,
|
||||||
// and prune the paths that do not appear in the index.
|
// and prune the paths that do not appear in the index.
|
||||||
let mut lastpath = String::new();
|
let mut lastpath = "";
|
||||||
let mut lastpathid = 0usize;
|
let mut lastpathid = 0usize;
|
||||||
|
|
||||||
for item in search_index {
|
let crate_items: Vec<&IndexItem> = search_index
|
||||||
|
.iter_mut()
|
||||||
|
.map(|item| {
|
||||||
item.parent_idx = item.parent.and_then(|defid| match defid_to_pathid.entry(defid) {
|
item.parent_idx = item.parent.and_then(|defid| match defid_to_pathid.entry(defid) {
|
||||||
Entry::Occupied(entry) => Some(*entry.get()),
|
Entry::Occupied(entry) => Some(*entry.get()),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
@ -98,14 +99,16 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Omit the parent path if it is same to that of the prior item.
|
// Omit the parent path if it is same to that of the prior item.
|
||||||
if lastpath == item.path {
|
if lastpath == &item.path {
|
||||||
item.path.clear();
|
item.path.clear();
|
||||||
} else {
|
} else {
|
||||||
lastpath = item.path.clone();
|
lastpath = &item.path;
|
||||||
}
|
|
||||||
crate_items.push(&*item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&*item
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
struct CrateData<'a> {
|
struct CrateData<'a> {
|
||||||
doc: String,
|
doc: String,
|
||||||
items: Vec<&'a IndexItem>,
|
items: Vec<&'a IndexItem>,
|
||||||
|
Loading…
Reference in New Issue
Block a user