Skip to content

Commit d80d61c

Browse files
committed
perf(headers): check for header literals before allocating name
1 parent 9338878 commit d80d61c

17 files changed

+111
-54
lines changed

src/header/common/access_control_allow_credentials.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ const ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE: UniCase<&'static str> = UniCase("tr
4242

4343
impl Header for AccessControlAllowCredentials {
4444
fn header_name() -> &'static str {
45-
"Access-Control-Allow-Credentials"
45+
static NAME: &'static str = "Access-Control-Allow-Credentials";
46+
NAME
4647
}
4748

4849
fn parse_header(raw: &[Vec<u8>]) -> ::Result<AccessControlAllowCredentials> {

src/header/common/authorization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl<S: Scheme> DerefMut for Authorization<S> {
7373

7474
impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'static {
7575
fn header_name() -> &'static str {
76-
"Authorization"
76+
static NAME: &'static str = "Authorization";
77+
NAME
7778
}
7879

7980
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Authorization<S>> {

src/header/common/cache_control.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ __hyper__deref!(CacheControl => Vec<CacheDirective>);
5151

5252
impl Header for CacheControl {
5353
fn header_name() -> &'static str {
54-
"Cache-Control"
54+
static NAME: &'static str = "Cache-Control";
55+
NAME
5556
}
5657

5758
fn parse_header(raw: &[Vec<u8>]) -> ::Result<CacheControl> {

src/header/common/content_disposition.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ pub struct ContentDisposition {
9090

9191
impl Header for ContentDisposition {
9292
fn header_name() -> &'static str {
93-
"Content-Disposition"
93+
static NAME: &'static str = "Content-Disposition";
94+
NAME
9495
}
9596

9697
fn parse_header(raw: &[Vec<u8>]) -> ::Result<ContentDisposition> {

src/header/common/content_length.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ use header::{Header, parsing};
3232
#[derive(Clone, Copy, Debug, PartialEq)]
3333
pub struct ContentLength(pub u64);
3434

35+
//static NAME: &'static str = "Content-Length";
36+
3537
impl Header for ContentLength {
3638
#[inline]
3739
fn header_name() -> &'static str {
38-
"Content-Length"
40+
static NAME: &'static str = "Content-Length";
41+
NAME
3942
}
4043
fn parse_header(raw: &[Vec<u8>]) -> ::Result<ContentLength> {
4144
// If multiple Content-Length headers were sent, everything can still

src/header/common/cookie.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ __hyper__deref!(Cookie => Vec<CookiePair>);
3939

4040
impl Header for Cookie {
4141
fn header_name() -> &'static str {
42-
"Cookie"
42+
static NAME: &'static str = "Cookie";
43+
NAME
4344
}
4445

4546
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Cookie> {

src/header/common/expect.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue");
3030

3131
impl Header for Expect {
3232
fn header_name() -> &'static str {
33-
"Expect"
33+
static NAME: &'static str = "Expect";
34+
NAME
3435
}
3536

3637
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Expect> {

src/header/common/host.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub struct Host {
4343

4444
impl Header for Host {
4545
fn header_name() -> &'static str {
46-
"Host"
46+
static NAME: &'static str = "Host";
47+
NAME
4748
}
4849

4950
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Host> {

src/header/common/if_range.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pub enum IfRange {
5555

5656
impl Header for IfRange {
5757
fn header_name() -> &'static str {
58-
"If-Range"
58+
static NAME: &'static str = "If-Range";
59+
NAME
5960
}
6061
fn parse_header(raw: &[Vec<u8>]) -> ::Result<IfRange> {
6162
let etag: ::Result<EntityTag> = header::parsing::from_one_raw_str(raw);

src/header/common/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ macro_rules! header {
217217
__hyper__deref!($id => Vec<$item>);
218218
impl $crate::header::Header for $id {
219219
fn header_name() -> &'static str {
220-
$n
220+
static NAME: &'static str = $n;
221+
NAME
221222
}
222223
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
223224
$crate::header::parsing::from_comma_delimited(raw).map($id)
@@ -243,7 +244,8 @@ macro_rules! header {
243244
__hyper__deref!($id => Vec<$item>);
244245
impl $crate::header::Header for $id {
245246
fn header_name() -> &'static str {
246-
$n
247+
static NAME: &'static str = $n;
248+
NAME
247249
}
248250
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
249251
$crate::header::parsing::from_comma_delimited(raw).map($id)
@@ -268,7 +270,8 @@ macro_rules! header {
268270
__hyper__deref!($id => $value);
269271
impl $crate::header::Header for $id {
270272
fn header_name() -> &'static str {
271-
$n
273+
static NAME: &'static str = $n;
274+
NAME
272275
}
273276
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
274277
$crate::header::parsing::from_one_raw_str(raw).map($id)
@@ -296,7 +299,8 @@ macro_rules! header {
296299
}
297300
impl $crate::header::Header for $id {
298301
fn header_name() -> &'static str {
299-
$n
302+
static NAME: &'static str = $n;
303+
NAME
300304
}
301305
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
302306
// FIXME: Return None if no item is in $id::Only

src/header/common/pragma.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub enum Pragma {
4040

4141
impl Header for Pragma {
4242
fn header_name() -> &'static str {
43-
"Pragma"
43+
static NAME: &'static str = "Pragma";
44+
NAME
4445
}
4546

4647
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Pragma> {

src/header/common/prefer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ __hyper__deref!(Prefer => Vec<Preference>);
5252

5353
impl Header for Prefer {
5454
fn header_name() -> &'static str {
55-
"Prefer"
55+
static NAME: &'static str = "Prefer";
56+
NAME
5657
}
5758

5859
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Prefer> {

src/header/common/preference_applied.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ __hyper__deref!(PreferenceApplied => Vec<Preference>);
5050

5151
impl Header for PreferenceApplied {
5252
fn header_name() -> &'static str {
53-
"Preference-Applied"
53+
static NAME: &'static str = "Preference-Applied";
54+
NAME
5455
}
5556

5657
fn parse_header(raw: &[Vec<u8>]) -> ::Result<PreferenceApplied> {

src/header/common/range.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl FromStr for ByteRangeSpec {
176176
impl Header for Range {
177177

178178
fn header_name() -> &'static str {
179-
"Range"
179+
static NAME: &'static str = "Range";
180+
NAME
180181
}
181182

182183
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Range> {

src/header/common/set_cookie.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ __hyper__deref!(SetCookie => Vec<CookiePair>);
8484

8585
impl Header for SetCookie {
8686
fn header_name() -> &'static str {
87-
"Set-Cookie"
87+
static NAME: &'static str = "Set-Cookie";
88+
NAME
8889
}
8990

9091
fn parse_header(raw: &[Vec<u8>]) -> ::Result<SetCookie> {

src/header/common/strict_transport_security.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ impl FromStr for StrictTransportSecurity {
121121

122122
impl Header for StrictTransportSecurity {
123123
fn header_name() -> &'static str {
124-
"Strict-Transport-Security"
124+
static NAME: &'static str = "Strict-Transport-Security";
125+
NAME
125126
}
126127

127128
fn parse_header(raw: &[Vec<u8>]) -> ::Result<StrictTransportSecurity> {

0 commit comments

Comments
 (0)