Implement to_managed without using an upcall function, as suggested by brson.
This commit is contained in:
parent
e9caa3fe2e
commit
07edf90367
|
@ -1869,11 +1869,6 @@ pub pure fn escape_unicode(s: &str) -> ~str {
|
||||||
move out
|
move out
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mod rustrt {
|
|
||||||
#[rust_stack]
|
|
||||||
pure fn upcall_str_new_shared(cstr: *libc::c_char, len: size_t) -> @str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unsafe operations
|
/// Unsafe operations
|
||||||
pub mod raw {
|
pub mod raw {
|
||||||
|
|
||||||
|
@ -2221,10 +2216,10 @@ impl &str: StrSlice {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn to_managed() -> @str {
|
pure fn to_managed() -> @str {
|
||||||
do str::as_buf(self) |p, _len| {
|
let v = at_vec::from_fn(self.len() + 1, |i| {
|
||||||
rustrt::upcall_str_new_shared(p as *libc::c_char,
|
if i == self.len() { 0 } else { self[i] }
|
||||||
self.len() as size_t)
|
});
|
||||||
}
|
unsafe { ::cast::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue