Skip to content

Commit 07edf90

Browse files
Dretchnikomatsakis
authored andcommitted
Implement to_managed without using an upcall function, as suggested by brson.
1 parent e9caa3f commit 07edf90

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/libcore/str.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1869,11 +1869,6 @@ pub pure fn escape_unicode(s: &str) -> ~str {
18691869
move out
18701870
}
18711871

1872-
extern mod rustrt {
1873-
#[rust_stack]
1874-
pure fn upcall_str_new_shared(cstr: *libc::c_char, len: size_t) -> @str;
1875-
}
1876-
18771872
/// Unsafe operations
18781873
pub mod raw {
18791874

@@ -2221,10 +2216,10 @@ impl &str: StrSlice {
22212216

22222217
#[inline]
22232218
pure fn to_managed() -> @str {
2224-
do str::as_buf(self) |p, _len| {
2225-
rustrt::upcall_str_new_shared(p as *libc::c_char,
2226-
self.len() as size_t)
2227-
}
2219+
let v = at_vec::from_fn(self.len() + 1, |i| {
2220+
if i == self.len() { 0 } else { self[i] }
2221+
});
2222+
unsafe { ::cast::transmute(v) }
22282223
}
22292224

22302225
#[inline]

0 commit comments

Comments
 (0)