summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2017-04-17 12:50:10 -0400
committerBen Gamari <ben@smart-cactus.org>2017-04-17 20:34:40 -0400
commitc87584f167ae6aee7b75d6ee4a39586b291543a0 (patch)
tree6f5c3d2dfa0399d25cb09fdf4f9a8442c08d55a1 /compiler/utils
parentf58176fe731e0412a04239be620443d63f067adf (diff)
downloadhaskell-c87584f167ae6aee7b75d6ee4a39586b291543a0.tar.gz
Use intersect and minus instead of filter
These are asymptotically better and convey the intent a bit better. Test Plan: ./validate Reviewers: simonpj, bgamari, austin, goldfire Reviewed By: bgamari Subscribers: rwbarton, thomie, simonmar Differential Revision: https://phabricator.haskell.org/D3455
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/UniqDFM.hs2
-rw-r--r--compiler/utils/UniqDSet.hs7
2 files changed, 6 insertions, 3 deletions
diff --git a/compiler/utils/UniqDFM.hs b/compiler/utils/UniqDFM.hs
index 9f81e4dca6..17f2747f83 100644
--- a/compiler/utils/UniqDFM.hs
+++ b/compiler/utils/UniqDFM.hs
@@ -294,7 +294,7 @@ intersectUDFM (UDFM x i) (UDFM y _j) = UDFM (M.intersection x y) i
-- M.intersection is left biased, that means the result will only have
-- a subset of elements from the left set, so `i` is a good upper bound.
-udfmIntersectUFM :: UniqDFM elt -> UniqFM elt -> UniqDFM elt
+udfmIntersectUFM :: UniqDFM elt1 -> UniqFM elt2 -> UniqDFM elt1
udfmIntersectUFM (UDFM x i) y = UDFM (M.intersection x (ufmToIntMap y)) i
-- M.intersection is left biased, that means the result will only have
-- a subset of elements from the left set, so `i` is a good upper bound.
diff --git a/compiler/utils/UniqDSet.hs b/compiler/utils/UniqDSet.hs
index 4e8c7ed97f..eef545eedd 100644
--- a/compiler/utils/UniqDSet.hs
+++ b/compiler/utils/UniqDSet.hs
@@ -20,7 +20,7 @@ module UniqDSet (
addOneToUniqDSet, addListToUniqDSet,
unionUniqDSets, unionManyUniqDSets,
minusUniqDSet, uniqDSetMinusUniqSet,
- intersectUniqDSets,
+ intersectUniqDSets, uniqDSetIntersectUniqSet,
intersectsUniqDSets,
foldUniqDSet,
elementOfUniqDSet,
@@ -69,12 +69,15 @@ unionManyUniqDSets sets = foldr1 unionUniqDSets sets
minusUniqDSet :: UniqDSet a -> UniqDSet a -> UniqDSet a
minusUniqDSet = minusUDFM
-uniqDSetMinusUniqSet :: UniqDSet a -> UniqSet a -> UniqDSet a
+uniqDSetMinusUniqSet :: UniqDSet a -> UniqSet b -> UniqDSet a
uniqDSetMinusUniqSet xs ys = udfmMinusUFM xs (getUniqSet ys)
intersectUniqDSets :: UniqDSet a -> UniqDSet a -> UniqDSet a
intersectUniqDSets = intersectUDFM
+uniqDSetIntersectUniqSet :: UniqDSet a -> UniqSet b -> UniqDSet a
+uniqDSetIntersectUniqSet xs ys = xs `udfmIntersectUFM` getUniqSet ys
+
intersectsUniqDSets :: UniqDSet a -> UniqDSet a -> Bool
intersectsUniqDSets = intersectsUDFM