Skip to content
Browse files

A silly micro-optimization in applyPattern'

  • Loading branch information...
1 parent ccf48c1 commit 957d65e7e181d464943eea3700fcc1f90067daa3 @Phlogistique committed May 20, 2012
Showing with 9 additions and 8 deletions.
  1. +8 −7 Muniq/Search.hs
  2. +1 −1 Muniq/Uniqed.hs
View
15 Muniq/Search.hs
@@ -54,10 +54,14 @@ subordinates p = foldl subordinates' ([],[])
ept :: [Pattern] -> Forest Pattern
ept xs = let (a,b) = partIntersect xs
in ept' a b
-ept' :: [Pattern] -> [Pattern] -> Forest Pattern
-ept' (x:xs) rest = let (a,b) = subordinates x rest
- in Node x (ept a) : ept' xs b
-ept' [] _ = []
+ where
+ partIntersect :: [Pattern] -> ([Pattern], [Pattern])
+ partIntersect = partRel intersect
+
+ ept' :: [Pattern] -> [Pattern] -> Forest Pattern
+ ept' (x:xs) rest = let (a,b) = subordinates x rest
+ in Node x (ept a) : ept' xs b
+ ept' [] _ = []
-- ceils a to a multiple of b
ceilMul :: Integral a => a -> a -> a
@@ -97,9 +101,6 @@ noIntersect :: [Pattern] -> [Pattern]
noIntersect (x:xs) = x : noIntersect (filter (not . intersect x) xs)
noIntersect xs = xs
-partIntersect :: [Pattern] -> ([Pattern], [Pattern])
-partIntersect = partRel intersect
-
-- What follows is dead code
cutPatternAt :: Pattern -> Int -> Maybe (Pattern, Pattern)
cutPatternAt p@(Pattern l s t) c | c < s || c >= patEnd p = Nothing
View
2 Muniq/Uniqed.hs
@@ -82,8 +82,8 @@ applyPattern = applyPattern' id
-- implementation of 'apt'
applyPattern' _ _ [] = Nothing
applyPattern' op p@(Pattern l s t) u = do (before,notbefore) <- splitU s u
- after <- dropU (patLen p) notbefore
gu <- takeU l notbefore
+ after <- dropU (l * (t - 1)) gu
return $ before ++ [Group t $ op gu] ++ after

0 comments on commit 957d65e

Please sign in to comment.
Something went wrong with that request. Please try again.