Skip to content

Commit 4e02046

Browse files
authored
refactor(header): remove BytesMut inline optimization when creating (#738)
`HeaderValue` from integers `::bytes::BytesMut >= 1` has no inline optimization
1 parent 091ee9a commit 4e02046

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/header/value.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::error::Error;
55
use std::fmt::Write;
66
use std::hash::{Hash, Hasher};
77
use std::str::FromStr;
8-
use std::{cmp, fmt, mem, str};
8+
use std::{cmp, fmt, str};
99

1010
use crate::header::name::HeaderName;
1111

@@ -424,27 +424,7 @@ macro_rules! from_integers {
424424
($($name:ident: $t:ident => $max_len:expr),*) => {$(
425425
impl From<$t> for HeaderValue {
426426
fn from(num: $t) -> HeaderValue {
427-
let mut buf = if mem::size_of::<BytesMut>() - 1 < $max_len {
428-
// On 32bit platforms, BytesMut max inline size
429-
// is 15 bytes, but the $max_len could be bigger.
430-
//
431-
// The likelihood of the number *actually* being
432-
// that big is very small, so only allocate
433-
// if the number needs that space.
434-
//
435-
// The largest decimal number in 15 digits:
436-
// It wold be 10.pow(15) - 1, but this is a constant
437-
// version.
438-
if num as u64 > 999_999_999_999_999_999 {
439-
BytesMut::with_capacity($max_len)
440-
} else {
441-
// fits inline...
442-
BytesMut::new()
443-
}
444-
} else {
445-
// full value fits inline, so don't allocate!
446-
BytesMut::new()
447-
};
427+
let mut buf = BytesMut::with_capacity($max_len);
448428
let _ = buf.write_str(::itoa::Buffer::new().format(num));
449429
HeaderValue {
450430
inner: buf.freeze(),

0 commit comments

Comments
 (0)