Skip to content

Commit 1673277

Browse files
committed
Make most of encode() non-generic to avoid heavy monomorphization costs
1 parent d6b3ece commit 1673277

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,11 @@ impl Encoding {
32683268
/// ```
32693269
#[cfg(feature = "alloc")]
32703270
pub fn encode<'a>(&'static self, string: impl Into<Cow<'a, str>>) -> (Cow<'a, [u8]>, &'static Encoding, bool) {
3271-
let string = string.into();
3271+
self.encode_(string.into())
3272+
}
3273+
3274+
/// Non-generic version of `encode`, to avoid monomorphizing a large amount of code many times.
3275+
fn encode_<'a>(&'static self, string: Cow<'a, str>) -> (Cow<'a, [u8]>, &'static Encoding, bool) {
32723276
let to_cow_bytes = |string: Cow<'a, str>| match string {
32733277
Cow::Owned(string) => Cow::Owned(string.into_bytes()),
32743278
Cow::Borrowed(str) => Cow::Borrowed(str.as_bytes()),

0 commit comments

Comments
 (0)