Skip to content

Commit

Permalink
Remove a bunch of unnecessary allocations and copies
Browse files Browse the repository at this point in the history
  • Loading branch information
dotdash committed May 30, 2013
1 parent ca74cbd commit 1720d9f
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
return false;

fn xfail_target() -> ~str {
~"xfail-" + str::to_owned(os::SYSNAME)
~"xfail-" + os::SYSNAME
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ fn parse_name_directive(line: &str, directive: &str) -> bool {

fn parse_name_value_directive(line: &str,
directive: ~str) -> Option<~str> {
let keycolon = directive + ~":";
let keycolon = directive + ":";
match str::find_str(line, keycolon) {
Some(colon) => {
let value = str::slice(line, colon + str::len(keycolon),
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
let mut env = os::env();

// Make sure we include the aux directory in the path
assert!(prog.ends_with(~".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ~".libaux";
assert!(prog.ends_with(".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";

env = do vec::map(env) |pair| {
let (k,v) = *pair;
if k == ~"PATH" { (~"PATH", v + ~";" + lib_path + ~";" + aux_path) }
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
else { (k,v) }
};
if str::ends_with(prog, "rustc.exe") {
Expand Down
13 changes: 6 additions & 7 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
was_expected = true;
}

if !was_expected && is_compiler_error_or_warning(str::to_owned(line)) {
if !was_expected && is_compiler_error_or_warning(line) {
fatal_ProcRes(fmt!("unexpected compiler error or warning: '%s'",
line),
ProcRes);
Expand Down Expand Up @@ -596,8 +596,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
}

fn make_exe_name(config: &config, testfile: &Path) -> Path {
Path(output_base_name(config, testfile).to_str() +
str::to_owned(os::EXE_SUFFIX))
Path(output_base_name(config, testfile).to_str() + os::EXE_SUFFIX)
}

fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
Expand All @@ -606,7 +605,7 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
// then split apart its command
let toolargs = split_maybe_args(&config.runtool);

let mut args = toolargs + ~[make_exe_name(config, testfile).to_str()];
let mut args = toolargs + [make_exe_name(config, testfile).to_str()];
let prog = args.shift();
return ProcArgs {prog: prog, args: args};
}
Expand Down Expand Up @@ -655,7 +654,7 @@ fn make_cmdline(_libpath: &str, prog: &str, args: &[~str]) -> ~str {
#[cfg(target_os = "win32")]
fn make_cmdline(libpath: &str, prog: &str, args: &[~str]) -> ~str {
fmt!("%s %s %s", lib_path_cmd_prefix(libpath), prog,
str::connect(args, ~" "))
str::connect(args, " "))
}

// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
Expand Down Expand Up @@ -776,8 +775,8 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
for args.args.each |tv| {
newcmd_out.push_str(" ");
newcmd_err.push_str(" ");
newcmd_out.push_str(tv.to_owned());
newcmd_err.push_str(tv.to_owned());
newcmd_out.push_str(*tv);
newcmd_err.push_str(*tv);
}

newcmd_out.push_str(" 2>/dev/null");
Expand Down
23 changes: 12 additions & 11 deletions src/libextra/getopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ pub struct Opt {
}

fn mkname(nm: &str) -> Name {
let unm = str::to_owned(nm);
return if nm.len() == 1u {
Short(str::char_at(unm, 0u))
} else { Long(unm) };
if nm.len() == 1u {
Short(str::char_at(nm, 0u))
} else {
Long(nm.to_owned())
}
}

/// Create an option that is required and takes an argument
Expand Down Expand Up @@ -195,19 +196,19 @@ pub enum Fail_ {
pub fn fail_str(f: Fail_) -> ~str {
return match f {
ArgumentMissing(ref nm) => {
~"Argument to option '" + *nm + "' missing."
fmt!("Argument to option '%s' missing.", *nm)
}
UnrecognizedOption(ref nm) => {
~"Unrecognized option: '" + *nm + "'."
fmt!("Unrecognized option: '%s'.", *nm)
}
OptionMissing(ref nm) => {
~"Required option '" + *nm + "' missing."
fmt!("Required option '%s' missing.", *nm)
}
OptionDuplicated(ref nm) => {
~"Option '" + *nm + "' given more than once."
fmt!("Option '%s' given more than once.", *nm)
}
UnexpectedArgument(ref nm) => {
~"Option " + *nm + " does not take an argument."
fmt!("Option '%s' does not take an argument.", *nm)
}
};
}
Expand Down Expand Up @@ -245,11 +246,11 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
let mut names;
let mut i_arg = None;
if cur[1] == '-' as u8 {
let tail = str::slice(cur, 2, curlen).to_owned();
let tail = str::slice(cur, 2, curlen);
let mut tail_eq = ~[];
for str::each_splitn_char(tail, '=', 1) |s| { tail_eq.push(s.to_owned()) }
if tail_eq.len() <= 1 {
names = ~[Long(tail)];
names = ~[Long(tail.to_owned())];
} else {
names =
~[Long(copy tail_eq[0])];
Expand Down
5 changes: 2 additions & 3 deletions src/libextra/net_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub mod v4 {
let input_is_inaddr_none =
result::get(&ip_rep_result).as_u32() == INADDR_NONE;

let new_addr = uv_ip4_addr(str::to_owned(ip), 22);
let new_addr = uv_ip4_addr(ip, 22);
let reformatted_name = uv_ip4_name(&new_addr);
debug!("try_parse_addr: input ip: %s reparsed ip: %s",
ip, reformatted_name);
Expand Down Expand Up @@ -259,7 +259,6 @@ pub mod v6 {
use uv_ip6_name = uv::ll::ip6_name;

use core::result;
use core::str;

/**
* Convert a str to `ip_addr`
Expand All @@ -285,7 +284,7 @@ pub mod v6 {
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
unsafe {
// need to figure out how to establish a parse failure..
let new_addr = uv_ip6_addr(str::to_owned(ip), 22);
let new_addr = uv_ip6_addr(ip, 22);
let reparsed_name = uv_ip6_name(&new_addr);
debug!("v6::try_parse_addr ip: '%s' reparsed '%s'",
ip, reparsed_name);
Expand Down
7 changes: 3 additions & 4 deletions src/libextra/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ fn get_path(rawurl: &str, authority: bool) ->
}
}

return Ok((decode_component(str::slice(rawurl, 0, end).to_owned()),
return Ok((decode_component(str::slice(rawurl, 0, end)),
str::slice(rawurl, end, len).to_owned()));
}

Expand All @@ -596,14 +596,13 @@ fn get_query_fragment(rawurl: &str) ->
if str::starts_with(rawurl, "#") {
let f = decode_component(str::slice(rawurl,
1,
str::len(rawurl)).to_owned());
str::len(rawurl)));
return Ok((~[], Some(f)));
} else {
return Ok((~[], None));
}
}
let (q, r) = split_char_first(str::slice(rawurl, 1,
str::len(rawurl)).to_owned(), '#');
let (q, r) = split_char_first(str::slice(rawurl, 1, rawurl.len()), '#');
let f = if str::len(r) != 0 {
Some(decode_component(r)) } else { None };
return Ok((query_from_str(q), f));
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ mod tests {
let mut left = len;
while left > 0u {
let take = (left + 1u) / 2u;
sh.input_str(str::slice(t.input, len - left,
take + len - left).to_owned());
sh.input_str(t.input.slice(len - left, take + len - left));
left = left - take;
}
let out = sh.result();
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {

let mut i = 0u;
while i < digits {
let range = str::char_range_at(str::to_owned(ss), pos);
let range = str::char_range_at(ss, pos);
pos = range.next;

match range.ch {
Expand Down Expand Up @@ -632,7 +632,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
}
}

do io::with_str_reader(str::to_owned(format)) |rdr| {
do io::with_str_reader(format) |rdr| {
let mut tm = Tm {
tm_sec: 0_i32,
tm_min: 0_i32,
Expand Down Expand Up @@ -844,7 +844,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
let mut buf = ~"";

do io::with_str_reader(str::to_owned(format)) |rdr| {
do io::with_str_reader(format) |rdr| {
while !rdr.eof() {
match rdr.read_char() {
'%' => buf += parse_type(rdr.read_char(), tm),
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct Logger {

pub impl Logger {
fn info(&self, i: &str) {
io::println(~"workcache: " + i.to_owned());
io::println(~"workcache: " + i);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,14 @@ pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: &str) -> ~str {


pub fn output_dll_filename(os: session::os, lm: LinkMeta) -> ~str {
let libname = fmt!("%s-%s-%s", lm.name, lm.extras_hash, lm.vers);
let (dll_prefix, dll_suffix) = match os {
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
session::os_android => (android::DLL_PREFIX, android::DLL_SUFFIX),
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return str::to_owned(dll_prefix) + libname +
str::to_owned(dll_suffix);
fmt!("%s%s-%s-%s%s", dll_prefix, lm.name, lm.extras_hash, lm.vers, dll_suffix)
}

// If the user wants an exe generated we need to invoke
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ pub fn type_to_str_inner(names: @TypeNames, outer0: &[TypeRef], ty: TypeRef)
let mut first: bool = true;
for tys.each |t| {
if first { first = false; } else { s += ", "; }
s += type_to_str_inner(names, outer, *t).to_owned();
s += type_to_str_inner(names, outer, *t);
}
// [Note at-str] FIXME #2543: Could rewrite this without the copy,
// but need better @str support.
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ pub fn list_file_metadata(intr: @ident_interner,
match get_metadata_section(os, path) {
option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out),
option::None => {
out.write_str(~"could not find metadata in "
+ path.to_str() + ".\n");
out.write_str(fmt!("could not find metadata in %s.\n", path.to_str()))
}
}
}
3 changes: 1 addition & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
let abbrev_len = 3u + estimate_sz(pos) + estimate_sz(len);
if abbrev_len < len {
// I.e. it's actually an abbreviation.
let s = ~"#" + uint::to_str_radix(pos, 16u) + ":" +
uint::to_str_radix(len, 16u) + "#";
let s = fmt!("#%x:%x#", pos, len);
let a = ty_abbrev { pos: pos, len: len, s: @s };
abbrevs.insert(t, a);
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {

// Add the clobbers to our constraints list
if clobbers != ~"" && constraints != ~"" {
constraints += ~"," + clobbers;
constraints += ",";
constraints += clobbers;
} else {
constraints += clobbers;
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2906,8 +2906,7 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
let cstore = sess.cstore;
while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; }
let mapname = if *sess.building_library {
mapmeta.name.to_owned() + "_" + mapmeta.vers.to_owned() + "_"
+ mapmeta.extras_hash.to_owned()
fmt!("%s_%s_%s", mapmeta.name, mapmeta.vers, mapmeta.extras_hash)
} else {
~"toplevel"
};
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/trans/cabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub impl FnType {
fn build_shim_args(&self, bcx: block,
arg_tys: &[TypeRef],
llargbundle: ValueRef) -> ~[ValueRef] {
let mut atys = /*bad*/copy self.arg_tys;
let mut attrs = /*bad*/copy self.attrs;
let mut atys: &[LLVMType] = self.arg_tys;
let mut attrs: &[option::Option<Attribute>] = self.attrs;

let mut llargvals = ~[];
let mut i = 0u;
Expand All @@ -71,8 +71,8 @@ pub impl FnType {
let llretptr = GEPi(bcx, llargbundle, [0u, n]);
let llretloc = Load(bcx, llretptr);
llargvals = ~[llretloc];
atys = vec::to_owned(atys.tail());
attrs = vec::to_owned(attrs.tail());
atys = atys.tail();
attrs = attrs.tail();
}

while i < n {
Expand Down Expand Up @@ -133,12 +133,12 @@ pub impl FnType {
ret_ty: TypeRef,
llwrapfn: ValueRef,
llargbundle: ValueRef) {
let mut atys = /*bad*/copy self.arg_tys;
let mut attrs = /*bad*/copy self.attrs;
let mut atys: &[LLVMType] = self.arg_tys;
let mut attrs: &[option::Option<Attribute>] = self.attrs;
let mut j = 0u;
let llretptr = if self.sret {
atys = vec::to_owned(atys.tail());
attrs = vec::to_owned(attrs.tail());
atys = atys.tail();
attrs = attrs.tail();
j = 1u;
get_param(llwrapfn, 0u)
} else if self.ret_ty.cast {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3661,8 +3661,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"bswap64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()),
ref other => {
tcx.sess.span_err(it.span,
~"unrecognized intrinsic function: `" +
(*other) + "`");
fmt!("unrecognized intrinsic function: `%s`",
*other));
return;
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ fn check_main_fn_ty(ccx: @mut CrateCtxt,
}
_ => {
tcx.sess.span_bug(main_span,
~"main has a non-function type: found `" +
ppaux::ty_to_str(tcx, main_t) + "`");
fmt!("main has a non-function type: found `%s`",
ppaux::ty_to_str(tcx, main_t)));
}
}
}
Expand Down Expand Up @@ -372,8 +372,8 @@ fn check_start_fn_ty(ccx: @mut CrateCtxt,
}
_ => {
tcx.sess.span_bug(start_span,
~"start has a non-function type: found `" +
ppaux::ty_to_str(tcx, start_t) + "`");
fmt!("start has a non-function type: found `%s`",
ppaux::ty_to_str(tcx, start_t)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_rptr(r, ref tm) => {
region_to_str_space(cx, "&", r) + mt_to_str(cx, tm)
}
ty_unboxed_vec(ref tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ">" }
ty_unboxed_vec(ref tm) => { fmt!("unboxed_vec<%s>", mt_to_str(cx, tm)) }
ty_type => ~"type",
ty_tup(ref elems) => {
let strs = elems.map(|elem| ty_to_str(cx, *elem));
Expand Down
Loading

5 comments on commit 1720d9f

@bors
Copy link
Contributor

@bors bors commented on 1720d9f May 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from sanxiyn
at dotdash@1720d9f

@bors
Copy link
Contributor

@bors bors commented on 1720d9f May 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging dotdash/rust/allocs = 1720d9f into auto

@bors
Copy link
Contributor

@bors bors commented on 1720d9f May 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotdash/rust/allocs = 1720d9f merged ok, testing candidate = 682afca

@bors
Copy link
Contributor

@bors bors commented on 1720d9f May 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 1720d9f May 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 682afca

Please sign in to comment.