Skip to content

Commit 0653e78

Browse files
committed
make Box<str>::clone simpler & safer
1 parent a23a77f commit 0653e78

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/liballoc/boxed.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,9 @@ impl<T: Clone> Clone for Box<T> {
395395
#[stable(feature = "box_slice_clone", since = "1.3.0")]
396396
impl Clone for Box<str> {
397397
fn clone(&self) -> Self {
398-
let len = self.len();
399-
let buf = RawVec::with_capacity(len);
398+
let buf: Box<[u8]> = self.as_bytes().into();
400399
unsafe {
401-
ptr::copy_nonoverlapping(self.as_ptr(), buf.ptr(), len);
402-
from_boxed_utf8_unchecked(buf.into_box())
400+
from_boxed_utf8_unchecked(buf)
403401
}
404402
}
405403
}

0 commit comments

Comments
 (0)