Cleanup, more descriptive names

This commit is contained in:
Magnus Hoff 2017-11-16 15:43:45 +01:00
parent df39e658cd
commit 29a6ec6725

View file

@ -38,9 +38,8 @@ struct MergeIterator<Item> {
left: Vec<diff::Result<Item>>, left: Vec<diff::Result<Item>>,
right: Vec<diff::Result<Item>>, right: Vec<diff::Result<Item>>,
a: usize, li: usize,
o: usize, ri: usize,
b: usize,
} }
impl<Item> MergeIterator<Item> { impl<Item> MergeIterator<Item> {
@ -48,9 +47,8 @@ impl<Item> MergeIterator<Item> {
MergeIterator { MergeIterator {
left, left,
right, right,
a: 0, li: 0,
o: 0, ri: 0,
b: 0,
} }
} }
} }
@ -63,50 +61,45 @@ where
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let mut i = 0; let mut i = 0;
while let (Some(&Both(..)), Some(&Both(..))) = (self.left.get(self.a+i), self.right.get(self.b+i)) { while let (Some(&Both(..)), Some(&Both(..))) = (self.left.get(self.li+i), self.right.get(self.ri+i)) {
i += 1; i += 1;
} }
if i > 0 { if i > 0 {
let chunk = ChunkItem::stable(Chunk(self.a..self.a+i, self.b..self.b+i)); let chunk = ChunkItem::stable(Chunk(self.li..self.li+i, self.ri..self.ri+i));
self.a += i; self.li += i;
self.o += i; self.ri += i;
self.b += i;
return Some(chunk); return Some(chunk);
} }
let mut a = self.a; let mut li = self.li;
let mut o = self.o; let mut ri = self.ri;
let mut b = self.b;
loop { loop {
match (self.left.get(a), self.right.get(b)) { match (self.left.get(li), self.right.get(ri)) {
(Some(&Right(_)), _) => { (Some(&Right(_)), _) => {
a += 1; li += 1;
}, },
(_, Some(&Right(_))) => { (_, Some(&Right(_))) => {
b += 1; ri += 1;
}, },
(Some(&Left(_)), Some(_)) => { (Some(&Left(_)), Some(_)) => {
a += 1; li += 1;
o += 1; ri += 1;
b += 1;
}, },
(Some(_), Some(&Left(_))) => { (Some(_), Some(&Left(_))) => {
a += 1; li += 1;
o += 1; ri += 1;
b += 1;
}, },
(Some(&Both(..)), Some(&Both(..))) => { (Some(&Both(..)), Some(&Both(..))) => {
let chunk = ChunkItem::unstable(Chunk(self.a..a, self.b..b)); let chunk = ChunkItem::unstable(Chunk(self.li..li, self.ri..ri));
self.a = a; self.li = li;
self.o = o; self.ri = ri;
self.b = b;
return Some(chunk); return Some(chunk);
} }
_ => { _ => {
if self.a < self.left.len() || self.b < self.right.len() { if self.li < self.left.len() || self.ri < self.right.len() {
let chunk = ChunkItem::unstable(Chunk(self.a..self.left.len(), self.b..self.right.len())); let chunk = ChunkItem::unstable(Chunk(self.li..self.left.len(), self.ri..self.right.len()));
self.a = self.left.len(); self.li = self.left.len();
self.b = self.right.len(); self.ri = self.right.len();
return Some(chunk); return Some(chunk);
} }
return None; return None;