Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/smol_str/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,17 +875,17 @@ 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`
len: unsafe { InlineSize::transmute_from_u8(len as u8) },
buf,
}
}
SmolStrBuilderRepr::Heap(heap) => Repr::new(heap),
SmolStrBuilderRepr::Heap(heap) => Repr::Heap(Arc::from(heap.into_boxed_str())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will allocate more, not less. Arc::from will allocate anyway, so this just has the extra allocation for into_boxed_str().

})
}

Expand Down