From 94269022a0837a1fde093f59263086f5066c36f4 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 11 Apr 2026 17:53:45 +0900 Subject: [PATCH] perf(bytestring): improve `From for String` performance --- bytestring/CHANGES.md | 1 + bytestring/src/lib.rs | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bytestring/CHANGES.md b/bytestring/CHANGES.md index b29e3e72..a06640be 100644 --- a/bytestring/CHANGES.md +++ b/bytestring/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - Minimum supported Rust version (MSRV) is now 1.88. +- Improve `From for String` performance. ## 1.5.0 diff --git a/bytestring/src/lib.rs b/bytestring/src/lib.rs index 10f5cc4b..16e26cf9 100644 --- a/bytestring/src/lib.rs +++ b/bytestring/src/lib.rs @@ -6,11 +6,7 @@ extern crate alloc; -use alloc::{ - boxed::Box, - string::{String, ToString}, - vec::Vec, -}; +use alloc::{boxed::Box, string::String, vec::Vec}; use core::{borrow::Borrow, fmt, hash, ops, str}; use bytes::Bytes; @@ -189,7 +185,7 @@ impl From> for ByteString { impl From for String { #[inline] fn from(value: ByteString) -> Self { - value.to_string() + String::from_utf8(value.0.into()).expect("ByteString invariant violated") } }