Skip to content

Commit 9c3679a

Browse files
committed
std: make str::append move self
This eliminates a copy and fixes a FIXME.
1 parent d573ecd commit 9c3679a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/libstd/str.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ pub trait OwnedStr {
20282028
fn pop_char(&mut self) -> char;
20292029
fn shift_char(&mut self) -> char;
20302030
fn unshift_char(&mut self, ch: char);
2031-
fn append(&self, rhs: &str) -> ~str; // FIXME #4850: this should consume self.
2031+
fn append(self, rhs: &str) -> ~str;
20322032
fn reserve(&mut self, n: uint);
20332033
fn reserve_at_least(&mut self, n: uint);
20342034
fn capacity(&self) -> uint;
@@ -2162,11 +2162,10 @@ impl OwnedStr for ~str {
21622162
21632163
/// Concatenate two strings together.
21642164
#[inline]
2165-
fn append(&self, rhs: &str) -> ~str {
2166-
// FIXME #4850: this should consume self, but that causes segfaults
2167-
let mut v = self.clone();
2168-
v.push_str_no_overallocate(rhs);
2169-
v
2165+
fn append(self, rhs: &str) -> ~str {
2166+
let mut new_str = self;
2167+
new_str.push_str_no_overallocate(rhs);
2168+
new_str
21702169
}
21712170
21722171
/**

0 commit comments

Comments
 (0)