Skip to content

Commit f31622a

Browse files
committed
Auto merge of #90813 - notriddle:notriddle/vec-extend, r=GuillaumeGomez
Use Vec extend and collect instead of repeatedly calling push
2 parents e4c23da + a82692d commit f31622a

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
443443
/// expands it.
444444
fn push(&mut self, row: PatStack<'p, 'tcx>) {
445445
if !row.is_empty() && row.head().is_or_pat() {
446-
for row in row.expand_or_pat() {
447-
self.patterns.push(row);
448-
}
446+
self.patterns.extend(row.expand_or_pat());
449447
} else {
450448
self.patterns.push(row);
451449
}

src/librustdoc/html/render/cache.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ crate enum ExternalLocation {
2626
/// Builds the search index from the collected metadata
2727
crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<'tcx>) -> String {
2828
let mut defid_to_pathid = FxHashMap::default();
29-
let mut crate_items = Vec::with_capacity(cache.search_index.len());
3029
let mut crate_paths = vec![];
3130

3231
// Attach all orphan items to the type's definition if the type
@@ -77,34 +76,38 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
7776

7877
// Reduce `DefId` in paths into smaller sequential numbers,
7978
// and prune the paths that do not appear in the index.
80-
let mut lastpath = String::new();
79+
let mut lastpath = "";
8180
let mut lastpathid = 0usize;
8281

83-
for item in search_index {
84-
item.parent_idx = item.parent.and_then(|defid| match defid_to_pathid.entry(defid) {
85-
Entry::Occupied(entry) => Some(*entry.get()),
86-
Entry::Vacant(entry) => {
87-
let pathid = lastpathid;
88-
entry.insert(pathid);
89-
lastpathid += 1;
82+
let crate_items: Vec<&IndexItem> = search_index
83+
.iter_mut()
84+
.map(|item| {
85+
item.parent_idx = item.parent.and_then(|defid| match defid_to_pathid.entry(defid) {
86+
Entry::Occupied(entry) => Some(*entry.get()),
87+
Entry::Vacant(entry) => {
88+
let pathid = lastpathid;
89+
entry.insert(pathid);
90+
lastpathid += 1;
9091

91-
if let Some(&(ref fqp, short)) = paths.get(&defid) {
92-
crate_paths.push((short, fqp.last().unwrap().clone()));
93-
Some(pathid)
94-
} else {
95-
None
92+
if let Some(&(ref fqp, short)) = paths.get(&defid) {
93+
crate_paths.push((short, fqp.last().unwrap().clone()));
94+
Some(pathid)
95+
} else {
96+
None
97+
}
9698
}
99+
});
100+
101+
// Omit the parent path if it is same to that of the prior item.
102+
if lastpath == &item.path {
103+
item.path.clear();
104+
} else {
105+
lastpath = &item.path;
97106
}
98-
});
99107

100-
// Omit the parent path if it is same to that of the prior item.
101-
if lastpath == item.path {
102-
item.path.clear();
103-
} else {
104-
lastpath = item.path.clone();
105-
}
106-
crate_items.push(&*item);
107-
}
108+
&*item
109+
})
110+
.collect();
108111

109112
struct CrateData<'a> {
110113
doc: String,

0 commit comments

Comments
 (0)