]> git.lizzy.rs Git - rust.git/commitdiff
Implement to_managed without using an upcall function, as suggested by brson.
authorGareth Daniel Smith <garethdanielsmith@gmail.com>
Sat, 6 Oct 2012 10:11:06 +0000 (11:11 +0100)
committerNiko Matsakis <niko@alum.mit.edu>
Sat, 13 Oct 2012 12:57:13 +0000 (05:57 -0700)
src/libcore/str.rs

index e2e7b15b1d7839920b458048838e863cfa8cf02a..447cb59acf80e414fc3dc597b8469a7b2e9057d6 100644 (file)
@@ -1869,11 +1869,6 @@ pub fn reserve_at_least(s: &mut ~str, n: uint) {
     move out
 }
 
-extern mod rustrt {
-    #[rust_stack]
-    pure fn upcall_str_new_shared(cstr: *libc::c_char, len: size_t) -> @str;
-}
-
 /// Unsafe operations
 pub mod raw {
 
@@ -2221,10 +2216,10 @@ impl &str: StrSlice {
 
     #[inline]
     pure fn to_managed() -> @str {
-        do str::as_buf(self) |p, _len| {
-            rustrt::upcall_str_new_shared(p as *libc::c_char,
-                                          self.len() as size_t)
-        }
+        let v = at_vec::from_fn(self.len() + 1, |i| {
+            if i == self.len() { 0 } else { self[i] }
+        });
+        unsafe { ::cast::transmute(v) }
     }
 
     #[inline]