Rollup merge of #126970 - DaniPopes:simplify-str-clone_into, r=cuviper · model-checking/verify-rust-std@8c3c7dc (original) (raw)

Original file line number Diff line number Diff line change
@@ -206,15 +206,16 @@ impl BorrowMut for String {
206 206 #[stable(feature = "rust1", since = "1.0.0")]
207 207 impl ToOwned for str {
208 208 type Owned = String;
209 +
209 210 #[inline]
210 211 fn to_owned(&self) -> String {
211 212 unsafe { String::from_utf8_unchecked(self.as_bytes().to_owned()) }
212 213 }
213 214
215 +#[inline]
214 216 fn clone_into(&self, target: &mut String) {
215 -let mut b = mem::take(target).into_bytes();
216 -self.as_bytes().clone_into(&mut b);
217 -*target = unsafe { String::from_utf8_unchecked(b) }
217 + target.clear();
218 + target.push_str(self);
218 219 }
219 220 }
220 221