File tree Expand file tree Collapse file tree 1 file changed +11
-23
lines changed Expand file tree Collapse file tree 1 file changed +11
-23
lines changed Original file line number Diff line number Diff line change @@ -451,30 +451,18 @@ foldl f = \ z0 ary0 -> go ary0 (length ary0 - 1) z0
451
451
{-# INLINE foldl #-}
452
452
453
453
-- We go to a bit of trouble here to avoid appending an extra mempty.
454
+ -- The below implementation is by Mateusz Kowalczyk, who indicates that
455
+ -- benchmarks show it to be faster than one that avoids lifting out
456
+ -- lst.
454
457
foldMap :: Monoid m => (a -> m ) -> Array a -> m
455
- foldMap f = \ ary0 ->
456
- let len = length ary0
457
- in if len == 0
458
- then mempty
459
- else go ary0 (len - 1 ) 0
460
- where
461
- go ary ! lst i
462
- | (# x # ) <- index# ary i
463
- , let fx = f x
464
- = if i == lst
465
- then fx
466
- else fx `mappend` go ary lst (i + 1 )
467
-
468
- {-
469
- case index# ary0 lst of
470
- (# xn #) -> go ary0 lst 0 (f xn)
471
- where
472
- go ary lst i z
473
- | i == lst = z
474
- | otherwise
475
- = case index# ary i of
476
- (# x #) -> f x `mappend` go ary lst (i + 1) z
477
- -}
458
+ foldMap f = \ ary0 -> case length ary0 of
459
+ 0 -> mempty
460
+ len ->
461
+ let ! lst = len - 1
462
+ go i | (# x # ) <- index# ary0 i, let fx = f x =
463
+ if i == lst then fx else fx `mappend` go (i + 1 )
464
+ in go 0
465
+ {-# INLINE foldMap #-}
478
466
479
467
undefinedElem :: a
480
468
undefinedElem = error " Data.HashMap.Array: Undefined element"
You can’t perform that action at this time.
0 commit comments