[commit: ghc] master: Define chkAppend, and use it (3d81b68)
Simon Peyton Jones
simonpj at microsoft.com
Thu May 30 23:33:02 CEST 2013
Repository : http://darcs.haskell.org/ghc.git/
On branch : master
https://github.com/ghc/ghc/commit/3d81b68d48e86f9dff032321aff20b76ad3ea081
>---------------------------------------------------------------
commit 3d81b68d48e86f9dff032321aff20b76ad3ea081
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Thu May 30 22:02:17 2013 +0100
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.
>---------------------------------------------------------------
compiler/types/FamInstEnv.lhs | 4 +---
compiler/utils/Util.lhs | 9 ++++++++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/compiler/types/FamInstEnv.lhs b/compiler/types/FamInstEnv.lhs
index 34f1701..6ccd44d 100644
--- a/compiler/types/FamInstEnv.lhs
+++ b/compiler/types/FamInstEnv.lhs
@@ -754,13 +754,11 @@ find match_fun match_tys (inst@(FamInst { fi_branches = branches, fi_branched =
where
match = FamInstMatch { fim_instance = inst
, fim_index = ind
- , fim_tys = substTyVars subst tvs `add_on` match_tys2}
+ , fim_tys = substTyVars subst tvs `chkAppend` match_tys2}
where
-- Deal with over-saturation
-- See Note [Over-saturated matches]
(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
:: MatchFun
diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs
index 90a2077..e2fd0aa 100644
--- a/compiler/utils/Util.lhs
+++ b/compiler/utils/Util.lhs
@@ -18,7 +18,7 @@ module Util (
unzipWith,
- mapFst, mapSnd,
+ mapFst, mapSnd, chkAppend,
mapAndUnzip, mapAndUnzip3, mapAccumL2,
nOfThem, filterOut, partitionWith, splitEithers,
@@ -259,6 +259,13 @@ splitEithers (e : es) = case e of
Left x -> (x:xs, ys)
Right y -> (xs, y:ys)
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}
A paranoid @zip@ (and some @zipWith@ friends) that checks the lists
More information about the ghc-commits
mailing list