Ben Franksen <[email protected]> added the comment: Following up with an optimized version.
1 patch for repository /home/franksen/src/darcs/screened-with-mitigation-of-issue2738: patch 697ac0eee2d3606c18fc2081bbf97ceee3945c0e Author: Ben Franksen <[email protected]> Date: Fri Jan 31 09:14:57 CET 2025 * minimize the amount of Maybe2 wrapping and unwrapping in merge for FLs This replaces the implementation in terms of the generic mergerFLFL with a direct one, at the cost of some (minor) code duplication. The implementation uses monadic style with the Identity functor in order to avoid nested case expressions. __________________________________ Darcs bug tracker <[email protected]> <https://bugs.darcs.net/patch2455> __________________________________
[minimize the amount of Maybe2 wrapping and unwrapping in merge for FLs Ben Franksen <[email protected]>**20250131081457 Ignore-this: 6fe0d49d2d01dc666a6b2d5090a87fa0fd6a5f854bf4599e62ff3e149b9f534435b80c3bc7f0dc40 This replaces the implementation in terms of the generic mergerFLFL with a direct one, at the cost of some (minor) code duplication. The implementation uses monadic style with the Identity functor in order to avoid nested case expressions. ] hunk ./src/Darcs/Patch/Merge.hs 28 +import Data.Functor.Identity ( Identity(..) ) hunk ./src/Darcs/Patch/Merge.hs 36 -import Darcs.Patch.Witnesses.Maybe +import Darcs.Patch.Witnesses.Maybe ( Maybe2(..) ) hunk ./src/Darcs/Patch/Merge.hs 43 - , mapFL_FL hunk ./src/Darcs/Patch/Merge.hs 140 - merge (ps :\/: qs) = - -- Wrapping the input patches with Maybe2 is done so that we can - -- (re-)use the existing merger* machinery below. - case mergerFLFL raiseMerge (mapFL_FL Just2 ps :\/: mapFL_FL Just2 qs) of - mqs' :/\: mps' -> catMaybesFL mqs' :/\: catMaybesFL mps' + merge = runIdentity . robustMergeFLFL hunk ./src/Darcs/Patch/Merge.hs 142 - raiseMerge (Nothing2 :\/: mq) = mq :/\: Nothing2 - raiseMerge (mp :\/: Nothing2) = Nothing2 :/\: mp - raiseMerge (Just2 p :\/: Just2 q) = robustMerge (p :\/: q) + robustMergeFLFL :: (FL p :\/: FL p) wX wY -> Identity ((FL p :/\: FL p) wX wY) + robustMergeFLFL (NilFL :\/: qs) = return $ qs :/\: NilFL + robustMergeFLFL ((p :>: ps) :\/: qs) = do + qs' :/\: mp' <- robustMergeFL (p :\/: qs) + ps' :/\: qs'' <- robustMergeFLFL (qs' :\/: ps) + return $ qs'' :/\: cons2 mp' ps' + + robustMergeFL :: (p :\/: FL p) wX wY -> Identity ((FL p :/\: Maybe2 p) wX wY) + robustMergeFL (p :\/: NilFL) = return $ NilFL :/\: Just2 p + robustMergeFL (p :\/: (q :>: qs)) = do + mq' :/\: mp' <- return $ robustMerge (p :\/: q) + case mp' of + Nothing2 -> return $ cons2 mq' qs :/\: Nothing2 + Just2 p' -> do + qs' :/\: mp'' <- robustMergeFL (p' :\/: qs) + return $ cons2 mq' qs' :/\: mp'' + + cons2 :: Maybe2 p wX wY -> FL p wY wZ -> FL p wX wZ + cons2 Nothing2 xs = xs + cons2 (Just2 x) xs = x :>: xs hunk ./src/Darcs/Patch/Witnesses/Maybe.hs 3 - , catMaybesFL hunk ./src/Darcs/Patch/Witnesses/Maybe.hs 24 - --- | Throw out the 'Nothing2's, keep what's in the 'Just2's. -catMaybesFL :: FL (Maybe2 p) wX wY -> FL p wX wY -catMaybesFL NilFL = NilFL -catMaybesFL (Nothing2 :>: ps) = catMaybesFL ps -catMaybesFL (Just2 p :>: ps) = p :>: catMaybesFL ps
minimize-the-amount-of-maybe2-wrapping-and-unwrapping-in-merge-for-fls.dpatch
Description: application/darcs-patch
_______________________________________________ darcs-devel mailing list [email protected] https://lists.darcs.net/mailman/listinfo/darcs-devel
