Skip to content

Commit 5ea8b3d

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

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3271,7 +3271,14 @@ impl Encoding {
32713271
&'static self,
32723272
string: impl Into<Cow<'a, str>>,
32733273
) -> (Cow<'a, [u8]>, &'static Encoding, bool) {
3274-
let string = string.into();
3274+
self.encode_(string.into())
3275+
}
3276+
3277+
/// Non-generic version of `encode`, to avoid monomorphizing a large amount of code many times.
3278+
fn encode_<'a>(
3279+
&'static self,
3280+
string: Cow<'a, str>,
3281+
) -> (Cow<'a, [u8]>, &'static Encoding, bool) {
32753282
let to_cow_bytes = |string: Cow<'a, str>| match string {
32763283
Cow::Owned(string) => Cow::Owned(string.into_bytes()),
32773284
Cow::Borrowed(str) => Cow::Borrowed(str.as_bytes()),

0 commit comments

Comments
 (0)