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

Bitmap: Use foldl' instead of foldr

These are producing StgWords so foldl' is the natural choice. I'm not
sure how I didn't notice this when I wrote D1041.

Test Plan: Validate

Reviewers: austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2955

GHC Trac Issues: #7450
parent 769e3ee7
......@@ -22,6 +22,7 @@ import SMRep
import DynFlags
import Util
import Data.Foldable (foldl')
import Data.Bits
{-|
......@@ -39,7 +40,10 @@ mkBitmap dflags stuff = chunkToBitmap dflags chunk : mkBitmap dflags rest
chunkToBitmap :: DynFlags -> [Bool] -> StgWord
chunkToBitmap dflags chunk =
foldr (.|.) (toStgWord dflags 0) [ toStgWord dflags 1 `shiftL` n | (True,n) <- zip chunk [0..] ]
foldl' (.|.) (toStgWord dflags 0) [ oneAt n | (True,n) <- zip chunk [0..] ]
where
oneAt :: Int -> StgWord
oneAt i = toStgWord dflags 1 `shiftL` i
-- | Make a bitmap where the slots specified are the /ones/ in the bitmap.
-- eg. @[0,1,3], size 4 ==> 0xb@.
......@@ -61,7 +65,7 @@ intsToBitmap dflags size = go 0
go !pos slots
| size <= pos = []
| otherwise =
(foldr (.|.) (toStgWord dflags 0) (map (\i->oneAt (i - pos)) these)) :
(foldl' (.|.) (toStgWord dflags 0) (map (\i->oneAt (i - pos)) these)) :
go (pos + word_sz) rest
where
(these,rest) = span (< (pos + word_sz)) slots
......@@ -87,7 +91,7 @@ intsToReverseBitmap dflags size = go 0
go !pos slots
| size <= pos = []
| otherwise =
(foldr xor (toStgWord dflags init) (map (\i->oneAt (i - pos)) these)) :
(foldl' xor (toStgWord dflags init) (map (\i->oneAt (i - pos)) these)) :
go (pos + word_sz) rest
where
(these,rest) = span (< (pos + word_sz)) slots
......
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