mirror of https://github.com/rwf2/Rocket.git
router: avoid sorting routes on add
This commit is contained in:
parent
944736208e
commit
621ef2ece8
|
@ -25,10 +25,8 @@ impl Router {
|
||||||
pub fn add(&mut self, route: Route) {
|
pub fn add(&mut self, route: Route) {
|
||||||
let selector = route.method;
|
let selector = route.method;
|
||||||
let entries = self.routes.entry(selector).or_insert_with(|| vec![]);
|
let entries = self.routes.entry(selector).or_insert_with(|| vec![]);
|
||||||
// TODO: We really just want an insertion at the correct spot here,
|
let insert_index = entries.binary_search_by_key(&route.rank, |r| r.rank).unwrap_or_else(|x| x);
|
||||||
// instead of pushing to the end and _then_ sorting.
|
entries.insert(insert_index, route);
|
||||||
entries.push(route);
|
|
||||||
entries.sort_by(|a, b| a.rank.cmp(&b.rank));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn route<'b>(&'b self, req: &Request) -> Vec<&'b Route> {
|
pub fn route<'b>(&'b self, req: &Request) -> Vec<&'b Route> {
|
||||||
|
|
Loading…
Reference in New Issue