From 8c9a8906daffb532b49b5a1d7fa248d7ec112c25 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 8 Apr 2016 15:00:17 -0400 Subject: [PATCH] Rewrite group2 in terms of spanIntersecting. --- src/Alignment.hs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 683d935ee..0e1e13b55 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -140,16 +140,10 @@ groupChildrenByLine ranges children | not (and $ null <$> ranges) group2 :: Join These [Range] -> [AlignedDiff leaf] -> (Join These [Range], [AlignedDiff leaf], [Join These (Range, [SplitDiff leaf Info])]) group2 ranges children | Just (headRanges, tailRanges) <- unconsThese ranges - , ((firstLine:rest):restOfChildren) <- children - , ~(l, r) <- split firstLine - = case fromThese False False . runJoin $ intersects headRanges firstLine of - (True, True) -> let (moreRanges, moreChildren, remainingLines) = group2 tailRanges (rest:restOfChildren) in - (moreRanges, moreChildren, pairRangesWithLine headRanges (pure <$> firstLine) : remainingLines) - (True, False) -> let (moreRanges, moreChildren, remainingLines) = group2 (modifyJoin (bimap (drop 1) (if null r then id else drop 1)) ranges) ((r ++ rest):restOfChildren) in - (moreRanges, moreChildren, pairRangesWithLine headRanges (mask firstLine $ modifyJoin (uncurry These . fromThese [] []) $ pure <$> head l) : remainingLines) - (False, True) -> let (moreRanges, moreChildren, remainingLines) = group2 (modifyJoin (bimap (if null l then id else drop 1) (drop 1)) ranges) ((l ++ rest):restOfChildren) in - (moreRanges, moreChildren, pairRangesWithLine headRanges (mask firstLine $ modifyJoin (uncurry These . fromThese [] []) $ pure <$> head r) : remainingLines) - _ -> (tailRanges, children, [ flip (,) [] <$> headRanges ]) + , ~(group, l, r, rest) <- spanThese (intersects headRanges) children + , Just merged <- (,) <$> headRanges `applyThese` fmap catMaybes (Join (uncurry These (unalign (runJoin <$> join group)))) + , ~(moreRanges, moreChildren, remainingLines) <- group2 (modifyJoin (bimap (if null l then id else drop 1) (if null r then id else drop 1)) ranges) (l ++ r ++ rest) + = (moreRanges, moreChildren, merged : remainingLines) | ([]:rest) <- children = group2 ranges rest | otherwise = ([] <$ ranges, children, fmap (flip (,) []) <$> sequenceL ranges)