From 9c3679a9a2caeacdd16735c64ab4837721287e64 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 23 Jul 2013 09:55:09 -0700 Subject: [PATCH] std: make str::append move self This eliminates a copy and fixes a FIXME. --- src/libstd/str.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 0d2cfa2e1e8..49a7eccaca8 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2028,7 +2028,7 @@ pub trait OwnedStr { fn pop_char(&mut self) -> char; fn shift_char(&mut self) -> char; fn unshift_char(&mut self, ch: char); - fn append(&self, rhs: &str) -> ~str; // FIXME #4850: this should consume self. + fn append(self, rhs: &str) -> ~str; fn reserve(&mut self, n: uint); fn reserve_at_least(&mut self, n: uint); fn capacity(&self) -> uint; @@ -2162,11 +2162,10 @@ impl OwnedStr for ~str { /// Concatenate two strings together. #[inline] - fn append(&self, rhs: &str) -> ~str { - // FIXME #4850: this should consume self, but that causes segfaults - let mut v = self.clone(); - v.push_str_no_overallocate(rhs); - v + fn append(self, rhs: &str) -> ~str { + let mut new_str = self; + new_str.push_str_no_overallocate(rhs); + new_str } /**