about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-12-18 02:46:26 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2013-12-19 10:18:02 +1100
commitb906a8b256e8e7a289bb7b0e4382f30c4bd0f431 (patch)
tree2b05006e2479b7597f7fad5eba61e9904ec602cd /src/libstd
parent17ac2aa523f03c386669f569bc89019deb0c0ecd (diff)
downloadrust-b906a8b256e8e7a289bb7b0e4382f30c4bd0f431.tar.gz
rust-b906a8b256e8e7a289bb7b0e4382f30c4bd0f431.zip
std::str: remove .as_mut_buf & rewrite/simplify `.push_char`.
`.as_mut_buf` was used exactly once, in `.push_char` which could be
written in a simpler way, using the `&mut ~[u8]` that it already
retrieved. In the rare situation when someone really needs
`.as_mut_buf`-like functionality (getting a `*mut u8`), they can go via
`str::raw::as_owned_vec`.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/str.rs29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index e90d3140077..78a09d459de 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -2555,14 +2555,6 @@ pub trait OwnedStr {
     /// The buffer does not have a null terminator.
     fn into_bytes(self) -> ~[u8];
 
-    /// Work with the mutable byte buffer and length of a slice.
-    ///
-    /// The buffer does not have a null terminator.
-    ///
-    /// The caller must make sure any mutations to this buffer keep the string
-    /// valid UTF-8!
-    fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T;
-
     /// Sets the length of a string
     ///
     /// This will explicitly set the size of the string, without actually
@@ -2591,16 +2583,15 @@ impl OwnedStr for ~str {
         let cur_len = self.len();
         // may use up to 4 bytes.
         unsafe {
-            raw::as_owned_vec(self).reserve_additional(4);
+            let v = raw::as_owned_vec(self);
+            v.reserve_additional(4);
 
             // Attempt to not use an intermediate buffer by just pushing bytes
             // directly onto this string.
-            let used = self.as_mut_buf(|buf, _| {
-                vec::raw::mut_buf_as_slice(buf.offset(cur_len as int), 4, |slc| {
-                    c.encode_utf8(slc)
-                })
-            });
-            self.set_len(cur_len + used);
+            let write_ptr = v.as_mut_ptr().offset(cur_len as int);
+            let used = vec::raw::mut_buf_as_slice(write_ptr, 4, |slc| c.encode_utf8(slc));
+
+            v.set_len(cur_len + used);
         }
     }
 
@@ -2669,14 +2660,6 @@ impl OwnedStr for ~str {
     }
 
     #[inline]
-    fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T {
-        unsafe {
-            let v = raw::as_owned_vec(self);
-            f(v.as_mut_ptr(), v.len())
-        }
-    }
-
-    #[inline]
     unsafe fn set_len(&mut self, new_len: uint) {
         raw::as_owned_vec(self).set_len(new_len)
     }