Start making moves explicit in libcore
This is in preparation for issue 2633. Replaced implicit moves that rely on last-use with explicit moves in char, float, and str.
This commit is contained in:
parent
2ba632a683
commit
2d116cbbed
@ -148,7 +148,7 @@ fn escape_unicode(c: char) -> ~str {
|
||||
str::push_str(out, str::from_char(c));
|
||||
for uint::range(str::len(s), pad) |_i| { str::push_str(out, ~"0"); }
|
||||
str::push_str(out, s);
|
||||
return out;
|
||||
move out
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,8 +181,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
|
||||
} else {
|
||||
acc = sign + ones + ~"." + racc;
|
||||
}
|
||||
|
||||
return acc;
|
||||
move acc
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,7 +228,7 @@ fn push_char(&s: ~str, ch: char) {
|
||||
pure fn from_char(ch: char) -> ~str {
|
||||
let mut buf = ~"";
|
||||
unchecked { push_char(buf, ch); }
|
||||
return buf;
|
||||
move buf
|
||||
}
|
||||
|
||||
/// Convert a vector of chars to a string
|
||||
@ -238,7 +238,7 @@ fn push_char(&s: ~str, ch: char) {
|
||||
reserve(buf, chs.len());
|
||||
for vec::each(chs) |ch| { push_char(buf, ch); }
|
||||
}
|
||||
return buf;
|
||||
move buf
|
||||
}
|
||||
|
||||
/// Appends a string slice to the back of a string, without overallocating
|
||||
@ -281,7 +281,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
|
||||
unchecked {
|
||||
push_str_no_overallocate(v, rhs);
|
||||
}
|
||||
return v;
|
||||
move v
|
||||
}
|
||||
|
||||
|
||||
@ -289,7 +289,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
|
||||
pure fn concat(v: &[~str]) -> ~str {
|
||||
let mut s: ~str = ~"";
|
||||
for vec::each(v) |ss| { unchecked { push_str(s, ss) }; }
|
||||
return s;
|
||||
move s
|
||||
}
|
||||
|
||||
/// Concatenate a vector of strings, placing a given separator between each
|
||||
@ -299,7 +299,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
|
||||
if first { first = false; } else { unchecked { push_str(s, sep); } }
|
||||
unchecked { push_str(s, ss) };
|
||||
}
|
||||
return s;
|
||||
move s
|
||||
}
|
||||
|
||||
/*
|
||||
@ -436,13 +436,11 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
*
|
||||
* The result vector is not null-terminated.
|
||||
*/
|
||||
pure fn to_bytes(s: &str) -> ~[u8] {
|
||||
unsafe {
|
||||
let mut s_copy = from_slice(s);
|
||||
let mut v: ~[u8] = ::unsafe::transmute(s_copy);
|
||||
vec::unsafe::set_len(v, len(s));
|
||||
return v;
|
||||
}
|
||||
pure fn to_bytes(s: &str) -> ~[u8] unsafe {
|
||||
let mut s_copy = from_slice(s);
|
||||
let mut v: ~[u8] = ::unsafe::transmute(s_copy);
|
||||
vec::unsafe::set_len(v, len(s));
|
||||
move v
|
||||
}
|
||||
|
||||
/// Work with the string as a byte slice, not including trailing null.
|
||||
@ -462,7 +460,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
unchecked { vec::push(buf, ch); }
|
||||
i = next;
|
||||
}
|
||||
return buf;
|
||||
move buf
|
||||
}
|
||||
|
||||
/**
|
||||
@ -539,7 +537,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
if allow_empty || start < l {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, start, l) ) };
|
||||
}
|
||||
result
|
||||
move result
|
||||
} else {
|
||||
splitn(s, |cur| cur == sep, count)
|
||||
}
|
||||
@ -582,7 +580,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
if allow_empty || start < l unchecked {
|
||||
vec::push(result, unsafe { unsafe::slice_bytes(s, start, l) });
|
||||
}
|
||||
result
|
||||
move result
|
||||
}
|
||||
|
||||
// See Issue #1932 for why this is a naive search
|
||||
@ -636,7 +634,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
do iter_between_matches(s, sep) |from, to| {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
|
||||
}
|
||||
result
|
||||
move result
|
||||
}
|
||||
|
||||
pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] {
|
||||
@ -646,7 +644,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
|
||||
}
|
||||
}
|
||||
result
|
||||
move result
|
||||
}
|
||||
|
||||
/**
|
||||
@ -665,7 +663,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
if l > 0u && s[l - 1u] == '\r' as u8 {
|
||||
unsafe { unsafe::set_len(cp, l - 1u); }
|
||||
}
|
||||
cp
|
||||
move cp
|
||||
})
|
||||
}
|
||||
|
||||
@ -707,7 +705,7 @@ fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
if first { first = false; } else { unchecked {push_str(result, to); }}
|
||||
unsafe { push_str(result, unsafe::slice_bytes(s, start, end)); }
|
||||
}
|
||||
result
|
||||
move result
|
||||
}
|
||||
|
||||
/*
|
||||
@ -865,7 +863,7 @@ impl @str : Ord {
|
||||
str::push_char(result, ff(cc));
|
||||
}
|
||||
}
|
||||
result
|
||||
move result
|
||||
}
|
||||
|
||||
/// Iterate over the bytes in a string
|
||||
@ -1517,7 +1515,7 @@ fn is_alphanumeric(s: &str) -> bool {
|
||||
vec::push_all(u, ~[w1, w2])
|
||||
}
|
||||
}
|
||||
return u;
|
||||
move u
|
||||
}
|
||||
|
||||
pure fn utf16_chars(v: &[u16], f: fn(char)) {
|
||||
@ -1551,7 +1549,7 @@ fn is_alphanumeric(s: &str) -> bool {
|
||||
reserve(buf, vec::len(v));
|
||||
utf16_chars(v, |ch| push_char(buf, ch));
|
||||
}
|
||||
return buf;
|
||||
move buf
|
||||
}
|
||||
|
||||
|
||||
@ -1931,7 +1929,7 @@ fn reserve_at_least(&s: ~str, n: uint) {
|
||||
reserve_at_least(out, str::len(s));
|
||||
chars_iter(s, |c| push_str(out, char::escape_default(c)));
|
||||
}
|
||||
return out;
|
||||
move out
|
||||
}
|
||||
|
||||
/// Escape each char in `s` with char::escape_unicode.
|
||||
@ -1941,7 +1939,7 @@ fn reserve_at_least(&s: ~str, n: uint) {
|
||||
reserve_at_least(out, str::len(s));
|
||||
chars_iter(s, |c| push_str(out, char::escape_unicode(c)));
|
||||
}
|
||||
return out;
|
||||
move out
|
||||
}
|
||||
|
||||
/// Unsafe operations
|
||||
|
Loading…
Reference in New Issue
Block a user