From ac50046a111a1ef6fb58b7e5f368ff6b9b55f89c Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 18 Oct 2012 11:04:32 -0700 Subject: [PATCH] Simplify str::to_managed --- src/libcore/str.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index d59f36e0681..d32d35cbe1a 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2262,9 +2262,8 @@ impl &str: StrSlice { #[inline] pure fn to_managed() -> @str { - let v = at_vec::from_fn(self.len() + 1, |i| { - if i == self.len() { 0 } else { self[i] } - }); + let bytes = as_bytes_slice(self); + let v = at_vec::from_fn(bytes.len(), |i| bytes[i]); unsafe { ::cast::transmute(v) } }