Skip to content

Commit

Permalink
fix: Don't initialize regex on each call to stream_readable (#1915)
Browse files Browse the repository at this point in the history
Each call takes ~1ms.
  • Loading branch information
larseggert authored May 27, 2024
1 parent ea1b2bb commit 0004f9a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions neqo-bin/src/server/http09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct HttpServer {
write_state: HashMap<StreamId, HttpStreamState>,
read_state: HashMap<StreamId, Vec<u8>>,
is_qns_test: bool,
regex: Regex,
}

impl HttpServer {
Expand Down Expand Up @@ -60,11 +61,17 @@ impl HttpServer {
qinfo!("ECHConfigList: {}", hex(cfg));
}

let is_qns_test = args.shared.qns_test.is_some();
Ok(Self {
server,
write_state: HashMap::new(),
read_state: HashMap::new(),
is_qns_test: args.shared.qns_test.is_some(),
is_qns_test,
regex: if is_qns_test {
Regex::new(r"GET +/(\S+)(?:\r)?\n").unwrap()
} else {
Regex::new(r"GET +/(\d+)(?:\r)?\n").unwrap()
},
})
}

Expand Down Expand Up @@ -144,12 +151,7 @@ impl HttpServer {
return;
};

let re = if self.is_qns_test {
Regex::new(r"GET +/(\S+)(?:\r)?\n").unwrap()
} else {
Regex::new(r"GET +/(\d+)(?:\r)?\n").unwrap()
};
let m = re.captures(msg);
let m = self.regex.captures(msg);
let Some(path) = m.and_then(|m| m.get(1)) else {
self.save_partial(stream_id, buf, conn);
return;
Expand Down

0 comments on commit 0004f9a

Please sign in to comment.