Unnamed repository; edit this file 'description' to name the repository.
Improve `Arc<str>` creation
While using `Into` could avoid an allocation in `String` -> `Box<str>`,
converting `Box<str>` into `Arc<str>` deallocates and re-allocates anyway.
| -rw-r--r-- | lib/smol_str/src/lib.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs index c0c61c80d7..e4cca47176 100644 --- a/lib/smol_str/src/lib.rs +++ b/lib/smol_str/src/lib.rs @@ -104,7 +104,7 @@ impl SmolStr { pub fn new<T>(text: T) -> SmolStr where - T: Into<String> + AsRef<str>, + T: AsRef<str>, { SmolStr(Repr::new(text)) } @@ -343,7 +343,7 @@ enum Repr { impl Repr { fn new<T>(text: T) -> Self where - T: Into<String> + AsRef<str>, + T: AsRef<str>, { { let text = text.as_ref(); @@ -367,7 +367,7 @@ impl Repr { } } - Repr::Heap(text.into().into_boxed_str().into()) + Repr::Heap(text.as_ref().into()) } #[inline(always)] |