diff --git a/src/header/map.rs b/src/header/map.rs index ea12a96c..4fa7b85a 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -445,8 +445,21 @@ impl HeaderMap { /// assert!(map.is_empty()); /// assert_eq!(0, map.capacity()); /// ``` + #[inline] pub fn new() -> Self { - HeaderMap::try_with_capacity(0).unwrap() + Self::default() + } +} + +impl Default for HeaderMap { + fn default() -> Self { + HeaderMap { + mask: 0, + indices: Box::new([]), // as a ZST, this doesn't actually allocate anything + entries: Vec::new(), + extra_values: Vec::new(), + danger: Danger::Green, + } } } @@ -501,13 +514,7 @@ impl HeaderMap { /// ``` pub fn try_with_capacity(capacity: usize) -> Result, MaxSizeReached> { if capacity == 0 { - Ok(HeaderMap { - mask: 0, - indices: Box::new([]), // as a ZST, this doesn't actually allocate anything - entries: Vec::new(), - extra_values: Vec::new(), - danger: Danger::Green, - }) + Ok(Self::default()) } else { let raw_cap = match to_raw_capacity(capacity).checked_next_power_of_two() { Some(c) => c, @@ -2164,12 +2171,6 @@ impl fmt::Debug for HeaderMap { } } -impl Default for HeaderMap { - fn default() -> Self { - HeaderMap::try_with_capacity(0).expect("zero capacity should never fail") - } -} - impl ops::Index for HeaderMap where K: AsHeaderName,