From 07edf9036715bde27cc7bbc0feb3ee6e461130da Mon Sep 17 00:00:00 2001 From: Gareth Daniel Smith Date: Sat, 6 Oct 2012 11:11:06 +0100 Subject: Implement to_managed without using an upcall function, as suggested by brson. --- src/libcore/str.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/str.rs b/src/libcore/str.rs index e2e7b15b1d7..447cb59acf8 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1869,11 +1869,6 @@ pub pure fn escape_unicode(s: &str) -> ~str { 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] -- cgit 1.4.1-3-g733a5