optimize back-reference filling
This commit is contained in:
parent
2d87f562f6
commit
909f3d76d8
@ -481,7 +481,7 @@ impl Handler for OnDemand {
|
|||||||
// for each incoming response
|
// for each incoming response
|
||||||
// 1. ensure verification data filled. (still TODO since on_demand doesn't use back-references yet)
|
// 1. ensure verification data filled. (still TODO since on_demand doesn't use back-references yet)
|
||||||
// 2. pending.requests.supply_response
|
// 2. pending.requests.supply_response
|
||||||
// 3. if extracted on-demand response
|
// 3. if extracted on-demand response, keep it for later.
|
||||||
for response in responses {
|
for response in responses {
|
||||||
match pending.requests.supply_response(&*self.cache, response) {
|
match pending.requests.supply_response(&*self.cache, response) {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@ -497,12 +497,14 @@ impl Handler for OnDemand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pending.requests.fill_unanswered();
|
||||||
if pending.requests.is_complete() {
|
if pending.requests.is_complete() {
|
||||||
let _ = pending.sender.send(pending.responses);
|
let _ = pending.sender.send(pending.responses);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update network requests (unless we're done, in which case fulfill the future.)
|
// update network requests (unless we're done, in which case fulfill the future.)
|
||||||
let mut builder = basic_request::RequestBuilder::default();
|
let mut builder = basic_request::RequestBuilder::default();
|
||||||
let num_answered = pending.requests.num_answered();
|
let num_answered = pending.requests.num_answered();
|
||||||
|
@ -115,6 +115,15 @@ impl<T: IncompleteRequest + Clone> Requests<T> {
|
|||||||
.expect("All outputs checked as invariant of `Requests` object; qed"))
|
.expect("All outputs checked as invariant of `Requests` object; qed"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sweep through all unanswered requests, filling them as necessary.
|
||||||
|
pub fn fill_unanswered(&mut self) {
|
||||||
|
let outputs = &mut self.outputs;
|
||||||
|
|
||||||
|
for req in self.requests.iter_mut().skip(self.answered) {
|
||||||
|
req.fill(|req_idx, out_idx| outputs.get(&(req_idx, out_idx)).cloned().ok_or(NoSuchOutput))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: super::CheckedRequest> Requests<T> {
|
impl<T: super::CheckedRequest> Requests<T> {
|
||||||
@ -141,8 +150,8 @@ impl<T: super::CheckedRequest> Requests<T> {
|
|||||||
|
|
||||||
self.answered += 1;
|
self.answered += 1;
|
||||||
|
|
||||||
// fill as much of each remaining request as we can.
|
// fill as much of the next request as we can.
|
||||||
for req in self.requests.iter_mut().skip(self.answered) {
|
if let Some(ref mut req) = self.requests.get_mut(self.answered) {
|
||||||
req.fill(|req_idx, out_idx| outputs.get(&(req_idx, out_idx)).cloned().ok_or(NoSuchOutput))
|
req.fill(|req_idx, out_idx| outputs.get(&(req_idx, out_idx)).cloned().ok_or(NoSuchOutput))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user