Skip to content

Commit

Permalink
make Box<str>::clone simpler & safer
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed May 27, 2019
1 parent a23a77f commit 0653e78
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/liballoc/boxed.rs
Expand Up @@ -395,11 +395,9 @@ impl<T: Clone> Clone for Box<T> {
#[stable(feature = "box_slice_clone", since = "1.3.0")]
impl Clone for Box<str> {
fn clone(&self) -> Self {
let len = self.len();
let buf = RawVec::with_capacity(len);
let buf: Box<[u8]> = self.as_bytes().into();
unsafe {
ptr::copy_nonoverlapping(self.as_ptr(), buf.ptr(), len);
from_boxed_utf8_unchecked(buf.into_box())
from_boxed_utf8_unchecked(buf)
}
}
}
Expand Down

0 comments on commit 0653e78

Please sign in to comment.