diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-05-27 09:43:20 +0300 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-05-27 21:17:12 +0300 |
| commit | 0653e78ae1b35eb50e06423052a34d807f1ac2af (patch) | |
| tree | d15f2e0c84cc4272fb6e96a155747c15f53475e8 /src/liballoc | |
| parent | a23a77fb19b24adb22d0a3d3886acac1a7a31f68 (diff) | |
| download | rust-0653e78ae1b35eb50e06423052a34d807f1ac2af.tar.gz rust-0653e78ae1b35eb50e06423052a34d807f1ac2af.zip | |
make Box<str>::clone simpler & safer
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 5affdbdb7e9..2f45ec7d643 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -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) } } } |
