Skip to content

Commit 4b9f533

Browse files
committed
Incorrectly and unnecessarily merged ancestor
1 parent 7965629 commit 4b9f533

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

src/core/haplotype.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -617,51 +617,38 @@ impl Mutant {
617617
.iter()
618618
.filter_map(|x| x.upgrade())
619619
.next(),
620-
_ => None,
620+
_ => return,
621621
};
622622

623-
let merger: [Option<&Mutant>; 3] = [
624-
descendant.as_ref().and_then(|x| x.try_unwrap_mutant()),
625-
Some(self),
626-
self.ancestor.try_unwrap_mutant(),
627-
];
623+
let descendant_inner = match descendant.as_ref().and_then(|x| x.try_unwrap_mutant()) {
624+
Some(x) => x,
625+
None => return,
626+
};
628627

629-
// if there is nothing to merge, return
630-
if merger[0].is_none() && merger[2].is_none() {
631-
return;
632-
}
628+
let merger: [&Mutant; 2] = [descendant_inner, self];
633629

634630
// aggregate changes
635631
let changes: HashMap<usize, (Symbol, Symbol)> = merger
636632
.iter()
637633
.rev()
638-
.flatten()
639634
.flat_map(|x| x.changes.iter())
640635
.map(|(position, change)| (*position, *change))
641636
.collect();
642637

643-
// last is the node furthest away from the wildtype
644-
// this node should be replaced, it is the node that may still be
645-
// visible
646-
let last = *merger.iter().flatten().next().unwrap();
647-
648-
// first is the node closest to the wildtype
649-
let first = *merger.iter().rev().flatten().next().unwrap();
650-
651638
// determine generation
652-
let generation = last.get_generation();
639+
let generation = descendant_inner.get_generation();
653640

654641
// extract ancestor and wildtype
655-
let ancestor = first.ancestor.clone();
656-
let wildtype = first.wildtype.clone();
642+
let ancestor = self.ancestor.clone();
643+
let wildtype = self.wildtype.clone();
657644

658645
// // we need to decrement the dirty descendants of the ancestor
659646
// // because it will be decremented when the previous node gets removed
660647
// ancestor.decrement_dirty_descendants();
661648

662649
// create new node
663650
unsafe {
664-
Mutant::new_and_replace(last, ancestor, wildtype, changes, generation);
651+
Mutant::new_and_replace(descendant_inner, ancestor, wildtype, changes, generation);
665652
};
666653
}
667654
}

0 commit comments

Comments
 (0)