Commit deb75cbf authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

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
parent 99f81828
......@@ -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
......
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