Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn batch(&mut self) {
- // it doesn't make sense to batch 0 or 1 actions
- if self.actions.len() < 2 {
- return;
- }
- let mut unbatched_actions = replace(&mut self.actions, vec![]);
- // sorting allows us to easily identify same-actions. Using operation as a
- // secondary sorting key enables to ensure we will pair same-actions and same-ops together.
- unbatched_actions.sort_by_key(|a| (a.data.field_name(), a.operation as u16));
- self.actions.push(unbatched_actions[0].clone());
- let mut j = 0;
- for unbatched in unbatched_actions.into_iter().skip(1) {
- loop {
- let mut action = &mut self.actions[j];
- match (
- &mut action.data,
- &unbatched.data,
- action.operation,
- unbatched.operation,
- ) {
- (Data::Tags(ref mut t1), Data::Tags(ref t2), op1, op2) if op1 == op2 => {
- t1.extend(t2.iter().cloned());
- }
- // it's perfectly valid to have multiple, separate tag operations
- (Data::Tags(_), Data::Tags(_), _, _) => {}
- (ref a, ref b, _, _) if a.field_name() == b.field_name() => {
- warn!("dropping unsupported batching of {}", a.field_name());
- }
- _ => {
- // self.actions.push(unbatched.clone());
- j += 1
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment