daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn batch(&mut self) {
  2.         // it doesn't make sense to batch 0 or 1 actions
  3.         if self.actions.len() < 2 {
  4.             return;
  5.         }
  6.  
  7.         let mut unbatched_actions = replace(&mut self.actions, vec![]);
  8.  
  9.         // sorting allows us to easily identify same-actions. Using operation as a
  10.         // secondary sorting key enables to ensure we will pair same-actions and same-ops together.
  11.         unbatched_actions.sort_by_key(|a| (a.data.field_name(), a.operation as u16));
  12.  
  13.         self.actions.push(unbatched_actions[0].clone());
  14.         let mut j = 0;
  15.         for unbatched in unbatched_actions.into_iter().skip(1) {
  16.             loop {
  17.                 let mut action = &mut self.actions[j];
  18.                 match (
  19.                     &mut action.data,
  20.                     &unbatched.data,
  21.                     action.operation,
  22.                     unbatched.operation,
  23.                 ) {
  24.                     (Data::Tags(ref mut t1), Data::Tags(ref t2), op1, op2) if op1 == op2 => {
  25.                         t1.extend(t2.iter().cloned());
  26.                     }
  27.                     // it's perfectly valid to have multiple, separate tag operations
  28.                     (Data::Tags(_), Data::Tags(_), _, _) => {}
  29.                     (ref a, ref b, _, _) if a.field_name() == b.field_name() => {
  30.                         warn!("dropping unsupported batching of {}", a.field_name());
  31.                     }
  32.                     _ => {
  33.                         // self.actions.push(unbatched.clone());
  34.                         j += 1
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top