Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9a1de08

Browse files
committed
rustc/driver: improve/remove allocations
1 parent 39753c8 commit 9a1de08

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

src/librustc_driver/driver.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,9 +1586,8 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
15861586
base.dedup();
15871587
}
15881588

1589-
base.into_iter()
1590-
.filter(|crate_type| {
1591-
let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);
1589+
base.retain(|crate_type| {
1590+
let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);
15921591

15931592
if !res {
15941593
session.warn(&format!(
@@ -1597,9 +1596,10 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
15971596
));
15981597
}
15991598

1600-
res
1601-
})
1602-
.collect()
1599+
res
1600+
});
1601+
1602+
base
16031603
}
16041604

16051605
pub fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {

src/librustc_driver/lib.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ pub mod target_features {
137137
codegen_backend: &dyn CodegenBackend) {
138138
let tf = Symbol::intern("target_feature");
139139

140-
for feat in codegen_backend.target_features(sess) {
141-
cfg.insert((tf, Some(feat)));
142-
}
140+
cfg.extend(codegen_backend.target_features(sess).into_iter().map(|feat| (tf, Some(feat))));
143141

144142
if sess.crt_static_feature() {
145143
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
@@ -997,7 +995,7 @@ impl RustcDefaultCalls {
997995
input: &Input)
998996
-> Compilation {
999997
let r = matches.opt_strs("Z");
1000-
if r.contains(&("ls".to_string())) {
998+
if r.iter().any(|s| *s == "ls") {
1001999
match input {
10021000
&Input::File(ref ifile) => {
10031001
let path = &(*ifile);
@@ -1085,8 +1083,7 @@ impl RustcDefaultCalls {
10851083
let allow_unstable_cfg = UnstableFeatures::from_environment()
10861084
.is_nightly_build();
10871085

1088-
let mut cfgs = Vec::new();
1089-
for &(name, ref value) in sess.parse_sess.config.iter() {
1086+
let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| {
10901087
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
10911088
ident: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)),
10921089
node: ast::MetaItemKind::Word,
@@ -1105,16 +1102,16 @@ impl RustcDefaultCalls {
11051102
let value = value.as_ref().map(|s| s.as_ref());
11061103
if name != "target_feature" || value != Some("crt-static") {
11071104
if !allow_unstable_cfg && gated_cfg.is_some() {
1108-
continue;
1105+
return None
11091106
}
11101107
}
11111108

1112-
cfgs.push(if let Some(value) = value {
1113-
format!("{}=\"{}\"", name, value)
1109+
if let Some(value) = value {
1110+
Some(format!("{}=\"{}\"", name, value))
11141111
} else {
1115-
name.to_string()
1116-
});
1117-
}
1112+
Some(name.to_string())
1113+
}
1114+
}).collect::<Vec<String>>();
11181115

11191116
cfgs.sort();
11201117
for cfg in cfgs {
@@ -1177,7 +1174,7 @@ fn usage(verbose: bool, include_unstable_options: bool) {
11771174
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
11781175
(option.apply)(&mut options);
11791176
}
1180-
let message = "Usage: rustc [OPTIONS] INPUT".to_string();
1177+
let message = "Usage: rustc [OPTIONS] INPUT";
11811178
let nightly_help = if nightly_options::is_nightly_build() {
11821179
"\n -Z help Print internal options for debugging rustc"
11831180
} else {
@@ -1192,7 +1189,7 @@ fn usage(verbose: bool, include_unstable_options: bool) {
11921189
-C help Print codegen options
11931190
-W help \
11941191
Print 'lint' options and default settings{}{}\n",
1195-
options.usage(&message),
1192+
options.usage(message),
11961193
nightly_help,
11971194
verbose_help);
11981195
}
@@ -1463,7 +1460,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
14631460
"the --no-stack-check flag is deprecated and does nothing");
14641461
}
14651462

1466-
if cg_flags.contains(&"passes=list".to_string()) {
1463+
if cg_flags.iter().any(|x| *x == "passes=list") {
14671464
get_codegen_sysroot("llvm")().print_passes();
14681465
return None;
14691466
}

src/librustc_driver/profile/trace.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ fn html_of_duration(_start: &Instant, dur: &Duration) -> (String, String) {
8989
)
9090
}
9191

92-
fn html_of_fraction(frac: f64) -> (String, String) {
92+
fn html_of_fraction(frac: f64) -> (String, &'static str) {
9393
let css = {
94-
if frac > 0.50 { "frac-50".to_string() }
95-
else if frac > 0.40 { "frac-40".to_string() }
96-
else if frac > 0.30 { "frac-30".to_string() }
97-
else if frac > 0.20 { "frac-20".to_string() }
98-
else if frac > 0.10 { "frac-10".to_string() }
99-
else if frac > 0.05 { "frac-05".to_string() }
100-
else if frac > 0.02 { "frac-02".to_string() }
101-
else if frac > 0.01 { "frac-01".to_string() }
102-
else if frac > 0.001 { "frac-001".to_string() }
103-
else { "frac-0".to_string() }
94+
if frac > 0.50 { "frac-50" }
95+
else if frac > 0.40 { "frac-40" }
96+
else if frac > 0.30 { "frac-30" }
97+
else if frac > 0.20 { "frac-20" }
98+
else if frac > 0.10 { "frac-10" }
99+
else if frac > 0.05 { "frac-05" }
100+
else if frac > 0.02 { "frac-02" }
101+
else if frac > 0.01 { "frac-01" }
102+
else if frac > 0.001 { "frac-001" }
103+
else { "frac-0" }
104104
};
105105
let percent = frac * 100.0;
106106
if percent > 0.1 { (format!("{:.1}%", percent), css) }
@@ -148,6 +148,7 @@ fn write_traces_rec(file: &mut File, traces: &[Rec], total: Duration, depth: usi
148148
}
149149

150150
fn compute_counts_rec(counts: &mut FxHashMap<String,QueryMetric>, traces: &[Rec]) {
151+
counts.reserve(traces.len());
151152
for t in traces.iter() {
152153
match t.effect {
153154
Effect::TimeBegin(ref msg) => {

0 commit comments

Comments
 (0)