From 5311b2d54af095f53cf2566ef8f2451e4d46cb40 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 3 Nov 2025 00:02:27 +0800 Subject: [PATCH] Avoid copy when convert owned String to Arc Signed-off-by: tison --- library/alloc/src/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 13b5cf23e72d8..b35beba54eca4 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3878,7 +3878,7 @@ impl From<&mut str> for Arc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From for Arc { - /// Allocates a reference-counted `str` and copies `v` into it. + /// Converts the given [`String`] to a shared reference-counted `str` slice. /// /// # Example /// @@ -3890,7 +3890,7 @@ impl From for Arc { /// ``` #[inline] fn from(v: String) -> Arc { - Arc::from(&v[..]) + Arc::from(v.into_boxed_str()) } }