From 17e8293ae1714503814080708b1647150ed56061 Mon Sep 17 00:00:00 2001 From: Cedric Erdelen Date: Tue, 2 Dec 2025 20:50:06 +0100 Subject: [PATCH] SmolStrBuilder: move rather than alloc + copy on finish Removing unnessecary len checks as well as 1 redundant alloc + copy on finishing a Builder into a SmolStr --- lib/smol_str/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs index 0d1f01a32b5a..4153c63e8c0c 100644 --- a/lib/smol_str/src/lib.rs +++ b/lib/smol_str/src/lib.rs @@ -875,9 +875,9 @@ impl SmolStrBuilder { /// Builds a [`SmolStr`] from `self`. #[must_use] - pub fn finish(&self) -> SmolStr { - SmolStr(match &self.0 { - &SmolStrBuilderRepr::Inline { len, buf } => { + pub fn finish(self) -> SmolStr { + SmolStr(match self.0 { + SmolStrBuilderRepr::Inline { len, buf } => { debug_assert!(len <= INLINE_CAP); Repr::Inline { // SAFETY: We know that `value.len` is less than or equal to the maximum value of `InlineSize` @@ -885,7 +885,7 @@ impl SmolStrBuilder { buf, } } - SmolStrBuilderRepr::Heap(heap) => Repr::new(heap), + SmolStrBuilderRepr::Heap(heap) => Repr::Heap(Arc::from(heap.into_boxed_str())), }) }