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
 | ||||
| 		//   1. ensure verification data filled. (still TODO since on_demand doesn't use back-references yet)
 | ||||
| 		//   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 { | ||||
| 			match pending.requests.supply_response(&*self.cache, response) { | ||||
| 				Ok(response) => { | ||||
| @ -497,12 +497,14 @@ impl Handler for OnDemand { | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		pending.requests.fill_unanswered(); | ||||
| 		if pending.requests.is_complete() { | ||||
| 			let _ = pending.sender.send(pending.responses); | ||||
| 
 | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		// update network requests (unless we're done, in which case fulfill the future.)
 | ||||
| 		let mut builder = basic_request::RequestBuilder::default(); | ||||
| 		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")) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/// 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> { | ||||
| @ -141,8 +150,8 @@ impl<T: super::CheckedRequest> Requests<T> { | ||||
| 
 | ||||
| 		self.answered += 1; | ||||
| 
 | ||||
| 		// fill as much of each remaining request as we can.
 | ||||
| 		for req in self.requests.iter_mut().skip(self.answered) { | ||||
| 		// fill as much of the next request as we can.
 | ||||
| 		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)) | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user