Skip to content

Commit

Permalink
Simplify Preference.addWeights.
Browse files Browse the repository at this point in the history
  • Loading branch information
grayjay committed Sep 12, 2016
1 parent d95d0e1 commit 2e5374e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cabal-install/Distribution/Solver/Modular/Preference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ addWeights fs = trav go
where
go :: TreeF a (Tree a) -> TreeF a (Tree a)
go (PChoiceF qpn@(Q _ pn) x cs) =
let versions = L.map version (W.keys cs)
sortedVersions = L.sortBy (flip compare) versions
let sortedVersions = L.sortBy (flip compare) $ L.map version (W.keys cs)
weights k = [f pn sortedVersions k | f <- fs]

elemsToWhnf :: [a] -> ()
elemsToWhnf = foldr seq ()
in PChoiceF qpn x
-- Evaluate the children's versions before evaluating any of the
-- subtrees, so that 'versions' doesn't hold onto all of the
-- subtrees, so that 'sortedVersions' doesn't hold onto all of the
-- subtrees (referenced by cs) and cause a space leak.
(elemsToWhnf versions `seq`
(elemsToWhnf sortedVersions `seq`
W.mapWeightsWithKey (\k w -> weights k ++ w) cs)
go x = x

Expand Down

0 comments on commit 2e5374e

Please sign in to comment.