Skip to content

Commit 44863ed

Browse files
committed
Avoid random vector construction
1 parent 7b6752d commit 44863ed

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/dist.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ impl Handler for Middleware {
3737

3838
// Second, if we're requesting html, then we've only got one page so
3939
// serve up that page. Otherwise proxy on to the rest of the app.
40-
let wants_html = {
41-
let content = req.headers().find("Accept").unwrap_or(Vec::new());
42-
content.iter().any(|s| s.contains("html"))
43-
};
40+
let wants_html = req.headers().find("Accept").map(|accept| {
41+
accept.iter().any(|s| s.contains("html"))
42+
}).unwrap_or(false);
4443
if wants_html {
4544
self.dist.call(&mut RequestProxy {
4645
other: req,

src/util/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ impl<'a> RequestUtils for Request + 'a {
9393
}
9494

9595
fn wants_json(&self) -> bool {
96-
let content = self.headers().find("Accept").unwrap_or(Vec::new());
97-
content.iter().any(|s| s.contains("json"))
96+
self.headers().find("Accept").map(|accept| {
97+
accept.iter().any(|s| s.contains("json"))
98+
}).unwrap_or(false)
9899
}
99100

100101
fn pagination(&self, default: usize, max: usize) -> CargoResult<(i64, i64)> {

0 commit comments

Comments
 (0)