Skip to content

Commit 5ea4197

Browse files
authored
Internal.Array: Don't return MArrays from loops (#377)
This prevents unnecessary MArray boxing.
1 parent 7237826 commit 5ea4197

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Data/HashMap/Internal/Array.hs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ map f = \ ary ->
442442
in run $ do
443443
mary <- new_ n
444444
go ary mary 0 n
445+
return mary
445446
where
446447
go ary mary i n
447-
| i >= n = return mary
448+
| i >= n = return ()
448449
| otherwise = do
449450
x <- indexM ary i
450451
write mary i $ f x
@@ -458,9 +459,10 @@ map' f = \ ary ->
458459
in run $ do
459460
mary <- new_ n
460461
go ary mary 0 n
462+
return mary
461463
where
462464
go ary mary i n
463-
| i >= n = return mary
465+
| i >= n = return ()
464466
| otherwise = do
465467
x <- indexM ary i
466468
write mary i $! f x
@@ -473,21 +475,23 @@ fromList n xs0 =
473475
run $ do
474476
mary <- new_ n
475477
go xs0 mary 0
478+
return mary
476479
where
477-
go [] !mary !_ = return mary
478-
go (x:xs) mary i = do write mary i x
479-
go xs mary (i+1)
480+
go [] !_ !_ = return ()
481+
go (x:xs) mary i = do write mary i x
482+
go xs mary (i+1)
480483

481484
fromList' :: Int -> [a] -> Array a
482485
fromList' n xs0 =
483486
CHECK_EQ("fromList'", n, Prelude.length xs0)
484487
run $ do
485488
mary <- new_ n
486489
go xs0 mary 0
490+
return mary
487491
where
488-
go [] !mary !_ = return mary
489-
go (!x:xs) mary i = do write mary i x
490-
go xs mary (i+1)
492+
go [] !_ !_ = return ()
493+
go (!x:xs) mary i = do write mary i x
494+
go xs mary (i+1)
491495

492496
-- | @since 0.2.17.0
493497
instance TH.Lift a => TH.Lift (Array a) where

0 commit comments

Comments
 (0)