diff options
| author | bors <bors@rust-lang.org> | 2013-05-20 23:55:20 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-20 23:55:20 -0700 |
| commit | 5a3e3205144969fe9a9ec724929d641f309a6162 (patch) | |
| tree | e8ba741b28071f02dc553238f8b3e24496f8b676 /src/libcore | |
| parent | d49a9dbc7ff342804112906760d87604f14f22c5 (diff) | |
| parent | 82fa0018c80c8f64cb1b446a7e59492d9ad97b1d (diff) | |
| download | rust-5a3e3205144969fe9a9ec724929d641f309a6162.tar.gz rust-5a3e3205144969fe9a9ec724929d641f309a6162.zip | |
auto merge of #6647 : alexcrichton/rust/unnecessary-alloc, r=graydon
This adds a lint mode for detecting unnecessary allocations on the heap. This isn't super fancy, currently it only has two rules 1. For a function's arguments, if you allocate a `[~|@]str` literal, when the type of the argument is a `&str`, emit a warning. 2. For the same case, emit warnings for boxed vectors when slices are required. After adding the lint, I rampaged through the libraries and removed all the unnecessary allocations I could find.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/os.rs | 2 | ||||
| -rw-r--r-- | src/libcore/str.rs | 2 | ||||
| -rw-r--r-- | src/libcore/unstable/extfmt.rs | 4 |
3 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs index b6943462f06..b2a30e50992 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -509,7 +509,7 @@ pub fn self_exe_path() -> Option<Path> { * Otherwise, homedir returns option::none. */ pub fn homedir() -> Option<Path> { - return match getenv(~"HOME") { + return match getenv("HOME") { Some(ref p) => if !str::is_empty(*p) { Some(Path(*p)) } else { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index a760ff8f262..53169554ec5 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1808,7 +1808,7 @@ pub fn to_utf16(s: &str) -> ~[u16] { ch -= 0x1_0000_u32; let w1 = 0xD800_u16 | ((ch >> 10) as u16); let w2 = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16); - u.push_all(~[w1, w2]) + u.push_all([w1, w2]) } } u diff --git a/src/libcore/unstable/extfmt.rs b/src/libcore/unstable/extfmt.rs index 1a1a89a413f..8da378fdc97 100644 --- a/src/libcore/unstable/extfmt.rs +++ b/src/libcore/unstable/extfmt.rs @@ -178,7 +178,7 @@ pub mod ct { i += 1; if i >= lim { - err(~"unterminated conversion at end of string"); + err("unterminated conversion at end of string"); } else if s[i] == '%' as u8 { push_slice(&mut pieces, s, h, i); i += 1; @@ -309,7 +309,7 @@ pub mod ct { pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) -> Parsed<Ty> { - if i >= lim { err(~"missing type in conversion"); } + if i >= lim { err("missing type in conversion"); } // FIXME (#2249): Do we really want two signed types here? // How important is it to be printf compatible? |
