]> git.lizzy.rs Git - rust.git/commitdiff
std: make str::append move self
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 23 Jul 2013 16:55:09 +0000 (09:55 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 23 Jul 2013 23:57:00 +0000 (16:57 -0700)
This eliminates a copy and fixes a FIXME.

src/libstd/str.rs

index 0d2cfa2e1e8fa660f29bf7a0c451eac7823869c1..49a7eccaca8a0c62fab4a28d841d20a043d94a1c 100644 (file)
@@ -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 @@ fn unshift_char(&mut self, ch: char) {
 
     /// 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
     }
 
     /**