perf(bytestring): improve `From<ByteString> for String` performance (#852)

This commit is contained in:
Yuki Okushi 2026-04-11 20:36:24 +09:00 committed by GitHub
parent cf12822c8d
commit 704bee0d84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 6 deletions

View File

@ -3,6 +3,7 @@
## Unreleased ## Unreleased
- Minimum supported Rust version (MSRV) is now 1.88. - Minimum supported Rust version (MSRV) is now 1.88.
- Improve `From<ByteString> for String` performance.
## 1.5.0 ## 1.5.0

View File

@ -6,11 +6,7 @@
extern crate alloc; extern crate alloc;
use alloc::{ use alloc::{boxed::Box, string::String, vec::Vec};
boxed::Box,
string::{String, ToString},
vec::Vec,
};
use core::{borrow::Borrow, fmt, hash, ops, str}; use core::{borrow::Borrow, fmt, hash, ops, str};
use bytes::Bytes; use bytes::Bytes;
@ -189,7 +185,7 @@ impl From<Box<str>> for ByteString {
impl From<ByteString> for String { impl From<ByteString> for String {
#[inline] #[inline]
fn from(value: ByteString) -> Self { fn from(value: ByteString) -> Self {
value.to_string() String::from_utf8(value.0.into()).expect("ByteString invariant violated")
} }
} }