Skip to content

Commit c5295f9

Browse files
committed
auto merge of #9717 : blake2-ppc/rust/rustc-static-str, r=alexcrichton
rustc: Use static strings in a few literals Avoid allocating extra copies of strings by using "" instead of ~"" for the debug options list and for the `time` function. This is a small change, but it is in a path that's always executed.
2 parents a9d54ac + 9ac175c commit c5295f9

File tree

6 files changed

+90
-91
lines changed

6 files changed

+90
-91
lines changed

src/librustc/back/link.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,9 @@ pub fn link_args(sess: Session,
10071007
continue;
10081008
}
10091009
let dir = cratepath.dirname();
1010-
if dir != ~"" { args.push(~"-L" + dir); }
1010+
if !dir.is_empty() { args.push("-L" + dir); }
10111011
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned());
1012-
args.push(~"-l" + libarg);
1012+
args.push("-l" + libarg);
10131013
}
10141014

10151015
let ula = cstore::get_used_link_args(cstore);
@@ -1032,12 +1032,12 @@ pub fn link_args(sess: Session,
10321032
// forces to make sure that library can be found at runtime.
10331033

10341034
for path in sess.opts.addl_lib_search_paths.iter() {
1035-
args.push(~"-L" + path.to_str());
1035+
args.push("-L" + path.to_str());
10361036
}
10371037

10381038
let rustpath = filesearch::rust_path();
10391039
for path in rustpath.iter() {
1040-
args.push(~"-L" + path.to_str());
1040+
args.push("-L" + path.to_str());
10411041
}
10421042

10431043
// The names of the extern libraries
@@ -1050,7 +1050,7 @@ pub fn link_args(sess: Session,
10501050
// On mac we need to tell the linker to let this library
10511051
// be rpathed
10521052
if sess.targ_cfg.os == session::OsMacos {
1053-
args.push(~"-Wl,-install_name,@rpath/"
1053+
args.push("-Wl,-install_name,@rpath/"
10541054
+ output.filename().unwrap());
10551055
}
10561056
}

src/librustc/driver/driver.rs

+39-39
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub enum input {
131131

132132
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
133133
-> ast::Crate {
134-
time(sess.time_passes(), ~"parsing", (), |_| {
134+
time(sess.time_passes(), "parsing", (), |_| {
135135
match *input {
136136
file_input(ref file) => {
137137
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
@@ -167,29 +167,29 @@ pub fn phase_2_configure_and_expand(sess: Session,
167167
// mod bar { macro_rules! baz!(() => {{}}) }
168168
//
169169
// baz! should not use this definition unless foo is enabled.
170-
crate = time(time_passes, ~"std macros injection", crate, |crate|
170+
crate = time(time_passes, "std macros injection", crate, |crate|
171171
syntax::ext::expand::inject_std_macros(sess.parse_sess,
172172
cfg.clone(),
173173
crate));
174174

175-
crate = time(time_passes, ~"configuration 1", crate, |crate|
175+
crate = time(time_passes, "configuration 1", crate, |crate|
176176
front::config::strip_unconfigured_items(crate));
177177

178-
crate = time(time_passes, ~"expansion", crate, |crate|
178+
crate = time(time_passes, "expansion", crate, |crate|
179179
syntax::ext::expand::expand_crate(sess.parse_sess, cfg.clone(),
180180
crate));
181181

182182
// strip again, in case expansion added anything with a #[cfg].
183-
crate = time(time_passes, ~"configuration 2", crate, |crate|
183+
crate = time(time_passes, "configuration 2", crate, |crate|
184184
front::config::strip_unconfigured_items(crate));
185185

186-
crate = time(time_passes, ~"maybe building test harness", crate, |crate|
186+
crate = time(time_passes, "maybe building test harness", crate, |crate|
187187
front::test::modify_for_testing(sess, crate));
188188

189-
crate = time(time_passes, ~"std injection", crate, |crate|
189+
crate = time(time_passes, "std injection", crate, |crate|
190190
front::std_inject::maybe_inject_libstd_ref(sess, crate));
191191

192-
crate = time(time_passes, ~"assigning node ids", crate, |crate|
192+
crate = time(time_passes, "assigning node ids", crate, |crate|
193193
front::assign_node_ids::assign_node_ids(sess, crate));
194194

195195
return crate;
@@ -211,37 +211,37 @@ pub fn phase_3_run_analysis_passes(sess: Session,
211211

212212
let time_passes = sess.time_passes();
213213

214-
let ast_map = time(time_passes, ~"ast indexing", (), |_|
214+
let ast_map = time(time_passes, "ast indexing", (), |_|
215215
syntax::ast_map::map_crate(sess.diagnostic(), crate));
216216

217-
time(time_passes, ~"external crate/lib resolution", (), |_|
217+
time(time_passes, "external crate/lib resolution", (), |_|
218218
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
219219
sess.filesearch,
220220
session::sess_os_to_meta_os(sess.targ_cfg.os),
221221
sess.opts.is_static,
222222
token::get_ident_interner()));
223223

224-
let lang_items = time(time_passes, ~"language item collection", (), |_|
224+
let lang_items = time(time_passes, "language item collection", (), |_|
225225
middle::lang_items::collect_language_items(crate, sess));
226226

227227
let middle::resolve::CrateMap {
228228
def_map: def_map,
229229
exp_map2: exp_map2,
230230
trait_map: trait_map
231231
} =
232-
time(time_passes, ~"resolution", (), |_|
232+
time(time_passes, "resolution", (), |_|
233233
middle::resolve::resolve_crate(sess, lang_items, crate));
234234

235-
time(time_passes, ~"looking for entry point", (),
235+
time(time_passes, "looking for entry point", (),
236236
|_| middle::entry::find_entry_point(sess, crate, ast_map));
237237

238-
let freevars = time(time_passes, ~"freevar finding", (), |_|
238+
let freevars = time(time_passes, "freevar finding", (), |_|
239239
freevars::annotate_freevars(def_map, crate));
240240

241-
let region_map = time(time_passes, ~"region resolution", (), |_|
241+
let region_map = time(time_passes, "region resolution", (), |_|
242242
middle::region::resolve_crate(sess, def_map, crate));
243243

244-
let rp_set = time(time_passes, ~"region parameterization inference", (), |_|
244+
let rp_set = time(time_passes, "region parameterization inference", (), |_|
245245
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
246246

247247
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
@@ -252,53 +252,53 @@ pub fn phase_3_run_analysis_passes(sess: Session,
252252
ty_cx, trait_map, crate);
253253

254254
// These next two const passes can probably be merged
255-
time(time_passes, ~"const marking", (), |_|
255+
time(time_passes, "const marking", (), |_|
256256
middle::const_eval::process_crate(crate, ty_cx));
257257

258-
time(time_passes, ~"const checking", (), |_|
258+
time(time_passes, "const checking", (), |_|
259259
middle::check_const::check_crate(sess, crate, ast_map, def_map,
260260
method_map, ty_cx));
261261

262262
let exported_items =
263-
time(time_passes, ~"privacy checking", (), |_|
263+
time(time_passes, "privacy checking", (), |_|
264264
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, crate));
265265

266-
time(time_passes, ~"effect checking", (), |_|
266+
time(time_passes, "effect checking", (), |_|
267267
middle::effect::check_crate(ty_cx, method_map, crate));
268268

269-
time(time_passes, ~"loop checking", (), |_|
269+
time(time_passes, "loop checking", (), |_|
270270
middle::check_loop::check_crate(ty_cx, crate));
271271

272-
time(time_passes, ~"stack checking", (), |_|
272+
time(time_passes, "stack checking", (), |_|
273273
middle::stack_check::stack_check_crate(ty_cx, crate));
274274

275275
let middle::moves::MoveMaps {moves_map, moved_variables_set,
276276
capture_map} =
277-
time(time_passes, ~"compute moves", (), |_|
277+
time(time_passes, "compute moves", (), |_|
278278
middle::moves::compute_moves(ty_cx, method_map, crate));
279279

280-
time(time_passes, ~"match checking", (), |_|
280+
time(time_passes, "match checking", (), |_|
281281
middle::check_match::check_crate(ty_cx, method_map,
282282
moves_map, crate));
283283

284-
time(time_passes, ~"liveness checking", (), |_|
284+
time(time_passes, "liveness checking", (), |_|
285285
middle::liveness::check_crate(ty_cx, method_map,
286286
capture_map, crate));
287287

288288
let (root_map, write_guard_map) =
289-
time(time_passes, ~"borrow checking", (), |_|
289+
time(time_passes, "borrow checking", (), |_|
290290
middle::borrowck::check_crate(ty_cx, method_map,
291291
moves_map, moved_variables_set,
292292
capture_map, crate));
293293

294-
time(time_passes, ~"kind checking", (), |_|
294+
time(time_passes, "kind checking", (), |_|
295295
kind::check_crate(ty_cx, method_map, crate));
296296

297297
let reachable_map =
298-
time(time_passes, ~"reachability checking", (), |_|
298+
time(time_passes, "reachability checking", (), |_|
299299
reachable::find_reachable(ty_cx, method_map, crate));
300300

301-
time(time_passes, ~"lint checking", (), |_|
301+
time(time_passes, "lint checking", (), |_|
302302
lint::check_crate(ty_cx, crate));
303303

304304
CrateAnalysis {
@@ -328,7 +328,7 @@ pub fn phase_4_translate_to_llvm(sess: Session,
328328
crate: ast::Crate,
329329
analysis: &CrateAnalysis,
330330
outputs: &OutputFilenames) -> CrateTranslation {
331-
time(sess.time_passes(), ~"translation", crate, |crate|
331+
time(sess.time_passes(), "translation", crate, |crate|
332332
trans::base::trans_crate(sess, crate, analysis,
333333
&outputs.obj_filename))
334334
}
@@ -349,7 +349,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
349349
let output_type = link::output_type_assembly;
350350
let asm_filename = outputs.obj_filename.with_filetype("s");
351351

352-
time(sess.time_passes(), ~"LLVM passes", (), |_|
352+
time(sess.time_passes(), "LLVM passes", (), |_|
353353
link::write::run_passes(sess,
354354
trans.context,
355355
trans.module,
@@ -363,7 +363,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
363363
os::remove_file(&asm_filename);
364364
}
365365
} else {
366-
time(sess.time_passes(), ~"LLVM passes", (), |_|
366+
time(sess.time_passes(), "LLVM passes", (), |_|
367367
link::write::run_passes(sess,
368368
trans.context,
369369
trans.module,
@@ -377,7 +377,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
377377
pub fn phase_6_link_output(sess: Session,
378378
trans: &CrateTranslation,
379379
outputs: &OutputFilenames) {
380-
time(sess.time_passes(), ~"linking", (), |_|
380+
time(sess.time_passes(), "linking", (), |_|
381381
link::link_binary(sess,
382382
&outputs.obj_filename,
383383
&outputs.out_filename,
@@ -596,12 +596,12 @@ pub fn build_target_config(sopts: @session::options,
596596
-> @session::config {
597597
let os = match get_os(sopts.target_triple) {
598598
Some(os) => os,
599-
None => early_error(demitter, ~"unknown operating system")
599+
None => early_error(demitter, "unknown operating system")
600600
};
601601
let arch = match get_arch(sopts.target_triple) {
602602
Some(arch) => arch,
603603
None => early_error(demitter,
604-
~"unknown architecture: " + sopts.target_triple)
604+
"unknown architecture: " + sopts.target_triple)
605605
};
606606
let (int_type, uint_type) = match arch {
607607
abi::X86 => (ast::ty_i32, ast::ty_u32),
@@ -686,7 +686,7 @@ pub fn build_session_options(binary: @str,
686686
let mut this_bit = 0u;
687687
for tuple in debug_map.iter() {
688688
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
689-
if name == debug_flag { this_bit = bit; break; }
689+
if *name == *debug_flag { this_bit = bit; break; }
690690
}
691691
if this_bit == 0u {
692692
early_error(demitter, format!("unknown debug flag: {}", *debug_flag))
@@ -726,7 +726,7 @@ pub fn build_session_options(binary: @str,
726726
No
727727
} else if matches.opt_present("O") {
728728
if matches.opt_present("opt-level") {
729-
early_error(demitter, ~"-O and --opt-level both provided");
729+
early_error(demitter, "-O and --opt-level both provided");
730730
}
731731
Default
732732
} else if matches.opt_present("opt-level") {
@@ -736,7 +736,7 @@ pub fn build_session_options(binary: @str,
736736
~"2" => Default,
737737
~"3" => Aggressive,
738738
_ => {
739-
early_error(demitter, ~"optimization level needs to be between 0-3")
739+
early_error(demitter, "optimization level needs to be between 0-3")
740740
}
741741
}
742742
} else { No }
@@ -1030,7 +1030,7 @@ pub fn build_output_filenames(input: &input,
10301030
}
10311031
}
10321032

1033-
pub fn early_error(emitter: @diagnostic::Emitter, msg: ~str) -> ! {
1033+
pub fn early_error(emitter: @diagnostic::Emitter, msg: &str) -> ! {
10341034
emitter.emit(None, msg, diagnostic::fatal);
10351035
fail2!();
10361036
}

src/librustc/driver/session.rs

+39-40
Original file line numberDiff line numberDiff line change
@@ -81,61 +81,60 @@ pub static no_vectorize_slp: uint = 1 << 28;
8181
pub static no_prepopulate_passes: uint = 1 << 29;
8282
pub static use_softfp: uint = 1 << 30;
8383

84-
pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
85-
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
86-
(~"time-passes", ~"measure time of each rustc pass", time_passes),
87-
(~"count-llvm-insns", ~"count where LLVM \
84+
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
85+
~[("verbose", "in general, enable more debug printouts", verbose),
86+
("time-passes", "measure time of each rustc pass", time_passes),
87+
("count-llvm-insns", "count where LLVM \
8888
instrs originate", count_llvm_insns),
89-
(~"time-llvm-passes", ~"measure time of each LLVM pass",
89+
("time-llvm-passes", "measure time of each LLVM pass",
9090
time_llvm_passes),
91-
(~"trans-stats", ~"gather trans statistics", trans_stats),
92-
(~"asm-comments", ~"generate comments into the assembly (may change behavior)", asm_comments),
93-
(~"no-verify", ~"skip LLVM verification", no_verify),
94-
(~"trace", ~"emit trace logs", trace),
95-
(~"coherence", ~"perform coherence checking", coherence),
96-
(~"borrowck-stats", ~"gather borrowck statistics", borrowck_stats),
97-
(~"borrowck-note-pure", ~"note where purity is req'd",
91+
("trans-stats", "gather trans statistics", trans_stats),
92+
("asm-comments", "generate comments into the assembly (may change behavior)", asm_comments),
93+
("no-verify", "skip LLVM verification", no_verify),
94+
("trace", "emit trace logs", trace),
95+
("coherence", "perform coherence checking", coherence),
96+
("borrowck-stats", "gather borrowck statistics", borrowck_stats),
97+
("borrowck-note-pure", "note where purity is req'd",
9898
borrowck_note_pure),
99-
(~"borrowck-note-loan", ~"note where loans are req'd",
99+
("borrowck-note-loan", "note where loans are req'd",
100100
borrowck_note_loan),
101-
(~"no-landing-pads", ~"omit landing pads for unwinding",
101+
("no-landing-pads", "omit landing pads for unwinding",
102102
no_landing_pads),
103-
(~"debug-llvm", ~"enable debug output from LLVM", debug_llvm),
104-
(~"count-type-sizes", ~"count the sizes of aggregate types",
103+
("debug-llvm", "enable debug output from LLVM", debug_llvm),
104+
("count-type-sizes", "count the sizes of aggregate types",
105105
count_type_sizes),
106-
(~"meta-stats", ~"gather metadata statistics", meta_stats),
107-
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
108-
(~"print-link-args", ~"Print the arguments passed to the linker", print_link_args),
109-
(~"gc", ~"Garbage collect shared data (experimental)", gc),
110-
(~"jit", ~"Execute using JIT (experimental)", jit),
111-
(~"extra-debug-info", ~"Extra debugging info (experimental)",
106+
("meta-stats", "gather metadata statistics", meta_stats),
107+
("no-opt", "do not optimize, even if -O is passed", no_opt),
108+
("print-link-args", "Print the arguments passed to the linker", print_link_args),
109+
("gc", "Garbage collect shared data (experimental)", gc),
110+
("jit", "Execute using JIT (experimental)", jit),
111+
("extra-debug-info", "Extra debugging info (experimental)",
112112
extra_debug_info),
113-
(~"debug-info", ~"Produce debug info (experimental)", debug_info),
114-
(~"static", ~"Use or produce static libraries or binaries " +
115-
"(experimental)", statik),
116-
(~"no-debug-borrows",
117-
~"do not show where borrow checks fail",
113+
("debug-info", "Produce debug info (experimental)", debug_info),
114+
("static", "Use or produce static libraries or binaries (experimental)", statik),
115+
("no-debug-borrows",
116+
"do not show where borrow checks fail",
118117
no_debug_borrows),
119-
(~"lint-llvm",
120-
~"Run the LLVM lint pass on the pre-optimization IR",
118+
("lint-llvm",
119+
"Run the LLVM lint pass on the pre-optimization IR",
121120
lint_llvm),
122-
(~"once-fns",
123-
~"Allow 'once fn' closures to deinitialize captured variables",
121+
("once-fns",
122+
"Allow 'once fn' closures to deinitialize captured variables",
124123
once_fns),
125-
(~"print-llvm-passes",
126-
~"Prints the llvm optimization passes being run",
124+
("print-llvm-passes",
125+
"Prints the llvm optimization passes being run",
127126
print_llvm_passes),
128-
(~"no-prepopulate-passes",
129-
~"Don't pre-populate the pass managers with a list of passes, only use \
127+
("no-prepopulate-passes",
128+
"Don't pre-populate the pass managers with a list of passes, only use \
130129
the passes from --passes",
131130
no_prepopulate_passes),
132-
(~"no-vectorize-loops",
133-
~"Don't run the loop vectorization optimization passes",
131+
("no-vectorize-loops",
132+
"Don't run the loop vectorization optimization passes",
134133
no_vectorize_loops),
135-
(~"no-vectorize-slp",
136-
~"Don't run LLVM's SLP vectorization passes",
134+
("no-vectorize-slp",
135+
"Don't run LLVM's SLP vectorization passes",
137136
no_vectorize_slp),
138-
(~"soft-float", ~"Generate software floating point library calls", use_softfp),
137+
("soft-float", "Generate software floating point library calls", use_softfp),
139138
]
140139
}
141140

0 commit comments

Comments
 (0)