Skip to content

Commit b6d06b7

Browse files
committed
Bug 1965246 - reduce allocations in neqo_glue::parse_headers r=valentin,necko-reviewers
Previously `neqo_glue::parse_headers` would allocate both header name and header value twice while parsing. With this commit, both are allocated only once. Differential Revision: https://phabricator.services.mozilla.com/D253684
1 parent 22bb81e commit b6d06b7

File tree

1 file changed

+10
-7
lines changed
  • netwerk/socket/neqo_glue/src

1 file changed

+10
-7
lines changed

netwerk/socket/neqo_glue/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,19 @@ fn parse_headers(headers: &nsACString) -> Result<Vec<Header>, nsresult> {
10241024
if elem.is_empty() {
10251025
continue;
10261026
}
1027-
let hdr_str: Vec<_> = elem.splitn(2, ':').collect();
1028-
let name = hdr_str[0].trim().to_lowercase();
1027+
1028+
let mut hdr_str = elem.splitn(2, ':');
1029+
let name = hdr_str
1030+
.next()
1031+
.expect("`elem` is not empty")
1032+
.trim()
1033+
.to_lowercase();
10291034
if is_excluded_header(&name) {
10301035
continue;
10311036
}
1032-
let value = if hdr_str.len() > 1 {
1033-
String::from(hdr_str[1].trim())
1034-
} else {
1035-
String::new()
1036-
};
1037+
let value = hdr_str
1038+
.next()
1039+
.map_or_else(String::new, |v| v.trim().to_string());
10371040

10381041
hdrs.push(Header::new(name, value));
10391042
}

0 commit comments

Comments
 (0)