diff options
| author | Gareth Daniel Smith <garethdanielsmith@gmail.com> | 2012-10-06 11:11:06 +0100 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-10-13 05:57:13 -0700 |
| commit | 07edf9036715bde27cc7bbc0feb3ee6e461130da (patch) | |
| tree | 5ecac7e01ee088c072f68eb88ba32cac089b3af7 /src/libcore | |
| parent | e9caa3fe2e291b7f2cea624bfd0dc879e95fe382 (diff) | |
Implement to_managed without using an upcall function, as suggested by brson.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str.rs | 13 |
1 files changed, 4 insertions, 9 deletions
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] |
