Commit 3d81b68d authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Define chkAppend, and use it

Somtimes we need (xs ++ ys) in situations where ys is
almost always empty.  Utils.chkAppend checks for that
case first.
parent 7849266c
...@@ -754,13 +754,11 @@ find match_fun match_tys (inst@(FamInst { fi_branches = branches, fi_branched = ...@@ -754,13 +754,11 @@ find match_fun match_tys (inst@(FamInst { fi_branches = branches, fi_branched =
where where
match = FamInstMatch { fim_instance = inst match = FamInstMatch { fim_instance = inst
, fim_index = ind , fim_index = ind
, fim_tys = substTyVars subst tvs `add_on` match_tys2} , fim_tys = substTyVars subst tvs `chkAppend` match_tys2}
where where
-- Deal with over-saturation -- Deal with over-saturation
-- See Note [Over-saturated matches] -- See Note [Over-saturated matches]
(match_tys1, match_tys2) = splitAtList mb_tcs match_tys (match_tys1, match_tys2) = splitAtList mb_tcs match_tys
add_on tys1 [] = tys1 -- The wildly common case
add_on tys1 tys2 = tys1 ++ tys2
lookup_fam_inst_env -- The worker, local to this module lookup_fam_inst_env -- The worker, local to this module
:: MatchFun :: MatchFun
......
...@@ -18,7 +18,7 @@ module Util ( ...@@ -18,7 +18,7 @@ module Util (
unzipWith, unzipWith,
mapFst, mapSnd, mapFst, mapSnd, chkAppend,
mapAndUnzip, mapAndUnzip3, mapAccumL2, mapAndUnzip, mapAndUnzip3, mapAccumL2,
nOfThem, filterOut, partitionWith, splitEithers, nOfThem, filterOut, partitionWith, splitEithers,
...@@ -259,6 +259,13 @@ splitEithers (e : es) = case e of ...@@ -259,6 +259,13 @@ splitEithers (e : es) = case e of
Left x -> (x:xs, ys) Left x -> (x:xs, ys)
Right y -> (xs, y:ys) Right y -> (xs, y:ys)
where (xs,ys) = splitEithers es where (xs,ys) = splitEithers es
chkAppend :: [a] -> [a] -> [a]
-- Checks for the second arguemnt being empty
-- Used in situations where that situation is common
chkAppend xs ys
| null ys = xs
| otherwise = xs ++ ys
\end{code} \end{code}
A paranoid @zip@ (and some @zipWith@ friends) that checks the lists A paranoid @zip@ (and some @zipWith@ friends) that checks the lists
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment