[commit: ghc] master: UniqSet: Implement unionManyUniqSets in terms of foldl' instead of foldr (deb75cb)
git at git.haskell.org
git at git.haskell.org
Tue Jan 24 21:07:56 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/deb75cbf6741d84859eb256f1773807b099ca12f/ghc
>---------------------------------------------------------------
commit deb75cbf6741d84859eb256f1773807b099ca12f
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Tue Jan 24 12:50:00 2017 -0500
UniqSet: Implement unionManyUniqSets in terms of foldl' instead of foldr
foldr generally isn't a good choice for folds where the result can't be
consumed incrementally. This gives a very modest improvement in
compiler allocations,
```
-1 s.d. ----- -0.182%
+1 s.d. ----- -0.050%
Average ----- -0.116%
```
This is clearly semantics-preserving since we are constructing a set.
Test Plan: Validate
Reviewers: austin
Subscribers: dfeuer, thomie
Differential Revision: https://phabricator.haskell.org/D2965
>---------------------------------------------------------------
deb75cbf6741d84859eb256f1773807b099ca12f
compiler/utils/UniqSet.hs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/compiler/utils/UniqSet.hs b/compiler/utils/UniqSet.hs
index f08fa86..6f58652 100644
--- a/compiler/utils/UniqSet.hs
+++ b/compiler/utils/UniqSet.hs
@@ -34,6 +34,7 @@ module UniqSet (
import UniqFM
import Unique
+import Data.Foldable (foldl')
{-
************************************************************************
@@ -90,19 +91,18 @@ type UniqSet a = UniqFM a
emptyUniqSet = emptyUFM
unitUniqSet x = unitUFM x x
-mkUniqSet = foldl addOneToUniqSet emptyUniqSet
+mkUniqSet = foldl' addOneToUniqSet emptyUniqSet
addOneToUniqSet set x = addToUFM set x x
addOneToUniqSet_C f set x = addToUFM_C f set x x
-addListToUniqSet = foldl addOneToUniqSet
+addListToUniqSet = foldl' addOneToUniqSet
delOneFromUniqSet = delFromUFM
delOneFromUniqSet_Directly = delFromUFM_Directly
delListFromUniqSet = delListFromUFM
unionUniqSets = plusUFM
-unionManyUniqSets [] = emptyUniqSet
-unionManyUniqSets sets = foldr1 unionUniqSets sets
+unionManyUniqSets = foldl' (flip unionUniqSets) emptyUniqSet
minusUniqSet = minusUFM
intersectUniqSets = intersectUFM
More information about the ghc-commits
mailing list