Skip to content

Commit db4dc1f

Browse files
committed
auto merge of #5443 : alexcrichton/rust/less-bad-copy, r=catamorphism
Removes a lot of instances of `/*bad*/ copy` throughout libsyntax/librustc. On the plus side, this shaves about 2s off of the runtime when compiling `librustc` with optimizations. Ideally I would have run a profiler to figure out which copies are the most critical to remove, but in reality there was a liberal amount of `git grep`s along with some spot checking and removing the easy ones.
2 parents 01e1798 + 3fac7cc commit db4dc1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+469
-472
lines changed

Diff for: src/librustc/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ pub mod write {
194194
let opts = sess.opts;
195195
if sess.time_llvm_passes() { llvm::LLVMRustEnableTimePasses(); }
196196
let mut pm = mk_pass_manager();
197-
let td = mk_target_data(
198-
/*bad*/copy sess.targ_cfg.target_strs.data_layout);
197+
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
199198
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
200199
// FIXME (#2812): run the linter here also, once there are llvm-c
201200
// bindings for it.
@@ -866,8 +865,9 @@ pub fn link_binary(sess: Session,
866865
// to be found at compile time so it is still entirely up to outside
867866
// forces to make sure that library can be found at runtime.
868867
869-
let addl_paths = /*bad*/copy sess.opts.addl_lib_search_paths;
870-
for addl_paths.each |path| { cc_args.push(~"-L" + path.to_str()); }
868+
for sess.opts.addl_lib_search_paths.each |path| {
869+
cc_args.push(~"-L" + path.to_str());
870+
}
871871
872872
// The names of the extern libraries
873873
let used_libs = cstore::get_used_libraries(cstore);

Diff for: src/librustc/back/rpath.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
4545
// where rustrt is and we know every rust program needs it
4646
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));
4747

48-
let target_triple = /*bad*/copy sess.opts.target_triple;
49-
let rpaths = get_rpaths(os, &sysroot, output, libs, target_triple);
48+
let rpaths = get_rpaths(os, &sysroot, output, libs,
49+
sess.opts.target_triple);
5050
rpaths_to_flags(rpaths)
5151
}
5252

@@ -140,8 +140,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
140140
let abs2 = abs2.normalize();
141141
debug!("finding relative path from %s to %s",
142142
abs1.to_str(), abs2.to_str());
143-
let split1 = /*bad*/copy abs1.components;
144-
let split2 = /*bad*/copy abs2.components;
143+
let split1: &[~str] = abs1.components;
144+
let split2: &[~str] = abs2.components;
145145
let len1 = vec::len(split1);
146146
let len2 = vec::len(split2);
147147
fail_unless!(len1 > 0);

Diff for: src/librustc/driver/driver.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,12 @@ pub fn build_configuration(sess: Session, +argv0: ~str, input: input) ->
132132
}
133133

134134
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
135-
fn parse_cfgspecs(cfgspecs: ~[~str],
135+
fn parse_cfgspecs(+cfgspecs: ~[~str],
136136
demitter: diagnostic::Emitter) -> ast::crate_cfg {
137-
let mut meta = ~[];
138-
for cfgspecs.each |s| {
137+
do vec::map_consume(cfgspecs) |s| {
139138
let sess = parse::new_parse_sess(Some(demitter));
140-
let m = parse::parse_meta_from_source_str(~"cfgspec", @/*bad*/ copy *s, ~[], sess);
141-
meta.push(m)
139+
parse::parse_meta_from_source_str(~"cfgspec", @s, ~[], sess)
142140
}
143-
return meta;
144141
}
145142

146143
pub enum input {
@@ -580,9 +577,9 @@ pub fn build_session_options(+binary: ~str,
580577
let debug_map = session::debugging_opts_map();
581578
for debug_flags.each |debug_flag| {
582579
let mut this_bit = 0u;
583-
for debug_map.each |pair| {
584-
let (name, _, bit) = /*bad*/copy *pair;
585-
if name == *debug_flag { this_bit = bit; break; }
580+
for debug_map.each |tuple| {
581+
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
582+
if name == debug_flag { this_bit = bit; break; }
586583
}
587584
if this_bit == 0u {
588585
early_error(demitter, fmt!("unknown debug flag: %s", *debug_flag))
@@ -647,7 +644,7 @@ pub fn build_session_options(+binary: ~str,
647644
let target =
648645
match target_opt {
649646
None => host_triple(),
650-
Some(ref s) => (/*bad*/copy *s)
647+
Some(s) => s
651648
};
652649
653650
let addl_lib_search_paths =

Diff for: src/librustc/lib/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ pub struct TargetData {
16471647
dtor: @target_data_res
16481648
}
16491649

1650-
pub fn mk_target_data(string_rep: ~str) -> TargetData {
1650+
pub fn mk_target_data(string_rep: &str) -> TargetData {
16511651
let lltd =
16521652
str::as_c_str(string_rep, |buf| unsafe {
16531653
llvm::LLVMCreateTargetData(buf)

Diff for: src/librustc/metadata/creader.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ fn visit_crate(e: @mut Env, c: ast::crate) {
142142
}
143143

144144
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
145-
match /*bad*/copy i.node {
146-
ast::view_item_extern_mod(ident, meta_items, id) => {
145+
match i.node {
146+
ast::view_item_extern_mod(ident, /*bad*/copy meta_items, id) => {
147147
debug!("resolving extern mod stmt. ident: %?, meta: %?",
148148
ident, meta_items);
149149
let cnum = resolve_crate(e, ident, meta_items, @~"", i.span);
@@ -154,8 +154,8 @@ fn visit_view_item(e: @mut Env, i: @ast::view_item) {
154154
}
155155

156156
fn visit_item(e: @mut Env, i: @ast::item) {
157-
match /*bad*/copy i.node {
158-
ast::item_foreign_mod(fm) => {
157+
match i.node {
158+
ast::item_foreign_mod(ref fm) => {
159159
match attr::foreign_abi(i.attrs) {
160160
either::Right(abi) => {
161161
if abi != ast::foreign_abi_cdecl &&

Diff for: src/librustc/metadata/encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
645645
debug!("encoding info for item at %s",
646646
ecx.tcx.sess.codemap.span_to_str(item.span));
647647
648-
match /*bad*/copy item.node {
648+
match item.node {
649649
item_const(_, _) => {
650650
add_to_index();
651651
ebml_w.start_tag(tag_items_data_item);
@@ -1196,10 +1196,10 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
11961196
if *attr::get_attr_name(attr) != ~"link" {
11971197
/*bad*/copy *attr
11981198
} else {
1199-
match /*bad*/copy attr.node.value.node {
1200-
meta_list(_, l) => {
1199+
match attr.node.value.node {
1200+
meta_list(_, ref l) => {
12011201
found_link_attr = true;;
1202-
synthesize_link_attr(ecx, l)
1202+
synthesize_link_attr(ecx, /*bad*/copy *l)
12031203
}
12041204
_ => /*bad*/copy *attr
12051205
}

Diff for: src/librustc/middle/astencode.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,14 @@ fn encode_vtable_origin(ecx: @e::EncodeContext,
639639
ebml_w: writer::Encoder,
640640
vtable_origin: typeck::vtable_origin) {
641641
do ebml_w.emit_enum(~"vtable_origin") {
642-
match /*bad*/copy vtable_origin {
643-
typeck::vtable_static(def_id, tys, vtable_res) => {
642+
match vtable_origin {
643+
typeck::vtable_static(def_id, ref tys, vtable_res) => {
644644
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
645645
do ebml_w.emit_enum_variant_arg(0u) {
646646
ebml_w.emit_def_id(def_id)
647647
}
648648
do ebml_w.emit_enum_variant_arg(1u) {
649-
ebml_w.emit_tys(ecx, /*bad*/copy tys);
649+
ebml_w.emit_tys(ecx, /*bad*/copy *tys);
650650
}
651651
do ebml_w.emit_enum_variant_arg(2u) {
652652
encode_vtable_res(ecx, ebml_w, vtable_res);

Diff for: src/librustc/middle/borrowck/gather_loans.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn req_loans_in_expr(ex: @ast::expr,
139139
}
140140

141141
// Special checks for various kinds of expressions:
142-
match /*bad*/copy ex.node {
142+
match ex.node {
143143
ast::expr_addr_of(mutbl, base) => {
144144
let base_cmt = self.bccx.cat_expr(base);
145145

@@ -150,10 +150,10 @@ fn req_loans_in_expr(ex: @ast::expr,
150150
visit::visit_expr(ex, self, vt);
151151
}
152152

153-
ast::expr_call(f, args, _) => {
153+
ast::expr_call(f, ref args, _) => {
154154
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
155155
let scope_r = ty::re_scope(ex.id);
156-
for vec::each2(args, arg_tys) |arg, arg_ty| {
156+
for vec::each2(*args, arg_tys) |arg, arg_ty| {
157157
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
158158
ast::by_ref => {
159159
let arg_cmt = self.bccx.cat_expr(*arg);
@@ -165,11 +165,11 @@ fn req_loans_in_expr(ex: @ast::expr,
165165
visit::visit_expr(ex, self, vt);
166166
}
167167

168-
ast::expr_method_call(rcvr, _, _, args, _) => {
168+
ast::expr_method_call(rcvr, _, _, ref args, _) => {
169169
let arg_tys = ty::ty_fn_args(ty::node_id_to_type(self.tcx(),
170170
ex.callee_id));
171171
let scope_r = ty::re_scope(ex.id);
172-
for vec::each2(args, arg_tys) |arg, arg_ty| {
172+
for vec::each2(*args, arg_tys) |arg, arg_ty| {
173173
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
174174
ast::by_ref => {
175175
let arg_cmt = self.bccx.cat_expr(*arg);

Diff for: src/librustc/middle/check_match.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
243243
}
244244
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
245245
let max_len = do m.foldr(0) |r, max_len| {
246-
match /*bad*/copy r[0].node {
247-
pat_vec(before, _, after) => {
246+
match r[0].node {
247+
pat_vec(ref before, _, ref after) => {
248248
uint::max(before.len() + after.len(), max_len)
249249
}
250250
_ => max_len
@@ -299,7 +299,7 @@ pub fn is_useful_specialized(cx: @MatchCheckCtxt,
299299
300300
pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
301301
let pat = raw_pat(p);
302-
match /*bad*/copy pat.node {
302+
match pat.node {
303303
pat_wild => { None }
304304
pat_ident(_, _, _) | pat_enum(_, _) => {
305305
match cx.tcx.def_map.find(&pat.id) {
@@ -324,7 +324,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
324324
pat_box(_) | pat_uniq(_) | pat_tup(_) | pat_region(*) => {
325325
Some(single)
326326
}
327-
pat_vec(before, slice, after) => {
327+
pat_vec(ref before, slice, ref after) => {
328328
match slice {
329329
Some(_) => None,
330330
None => Some(vec(before.len() + after.len()))
@@ -448,8 +448,8 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
448448
}
449449
450450
pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
451-
match /*bad*/copy ty::get(ty).sty {
452-
ty::ty_tup(fs) => fs.len(),
451+
match ty::get(ty).sty {
452+
ty::ty_tup(ref fs) => fs.len(),
453453
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) => 1u,
454454
ty::ty_enum(eid, _) => {
455455
let id = match ctor { variant(id) => id,
@@ -704,7 +704,7 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
704704
_ => ()
705705
}
706706
707-
match /*bad*/copy pat.node {
707+
match pat.node {
708708
pat_box(sub) | pat_uniq(sub) | pat_region(sub) |
709709
pat_ident(_, _, Some(sub)) => {
710710
is_refutable(cx, sub)
@@ -715,13 +715,13 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
715715
false
716716
}
717717
pat_lit(_) | pat_range(_, _) => { true }
718-
pat_struct(_, fields, _) => {
718+
pat_struct(_, ref fields, _) => {
719719
fields.any(|f| is_refutable(cx, f.pat))
720720
}
721-
pat_tup(elts) => {
721+
pat_tup(ref elts) => {
722722
elts.any(|elt| is_refutable(cx, *elt))
723723
}
724-
pat_enum(_, Some(args)) => {
724+
pat_enum(_, Some(ref args)) => {
725725
args.any(|a| is_refutable(cx, *a))
726726
}
727727
pat_enum(_,_) => { false }

Diff for: src/librustc/middle/const_eval.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn classify(e: @expr,
8181
Some(x) => x,
8282
None => {
8383
let cn =
84-
match /*bad*/copy e.node {
84+
match e.node {
8585
ast::expr_lit(lit) => {
8686
match lit.node {
8787
ast::lit_str(*) |
@@ -101,9 +101,9 @@ pub fn classify(e: @expr,
101101
classify(b, def_map, tcx))
102102
}
103103

104-
ast::expr_tup(es) |
105-
ast::expr_vec(es, ast::m_imm) => {
106-
join_all(vec::map(es, |e| classify(*e, def_map, tcx)))
104+
ast::expr_tup(ref es) |
105+
ast::expr_vec(ref es, ast::m_imm) => {
106+
join_all(vec::map(*es, |e| classify(*e, def_map, tcx)))
107107
}
108108

109109
ast::expr_vstore(e, vstore) => {

Diff for: src/librustc/middle/freevars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
5656
Some(df) => {
5757
let mut def = df;
5858
while i < depth {
59-
match copy def {
59+
match def {
6060
ast::def_upvar(_, inner, _, _) => { def = *inner; }
6161
_ => break
6262
}

Diff for: src/librustc/middle/lint.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ pub impl Context {
360360
let metas =
361361
attr::attr_metas(attr::find_attrs_by_name(attrs, level_name));
362362
for metas.each |meta| {
363-
match /*bad*/copy meta.node {
364-
ast::meta_list(_, metas) => {
363+
match meta.node {
364+
ast::meta_list(_, ref metas) => {
365365
for metas.each |meta| {
366366
match meta.node {
367367
ast::meta_word(ref lintname) => {
@@ -653,8 +653,8 @@ fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
653653
}
654654

655655
fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
656-
match /*bad*/copy item.node {
657-
ast::item_trait(_, _, methods) => {
656+
match item.node {
657+
ast::item_trait(_, _, ref methods) => {
658658
for methods.each |method| {
659659
match *method {
660660
ast::required(*) => {}

0 commit comments

Comments
 (0)