Skip to content

Commit

Permalink
Implement to_managed without using an upcall function, as suggested b…
Browse files Browse the repository at this point in the history
…y brson.
  • Loading branch information
Dretch authored and nikomatsakis committed Oct 13, 2012
1 parent e9caa3f commit 07edf90
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 07edf90

Please sign in to comment.