mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-28 04:57:14 +03:00
Optimize "foldl"
This commit is contained in:
parent
103c80090a
commit
89470ff672
@ -182,7 +182,7 @@ foldl step init rowDes =
|
||||
maxCols <- LibPQ.nfields result
|
||||
accRef <- newIORef init
|
||||
failureRef <- newIORef Nothing
|
||||
forM_ [0 .. pred (rowToInt maxRows)] $ \rowIndex -> do
|
||||
forMFromZero_ (rowToInt maxRows) $ \rowIndex -> do
|
||||
rowResult <- Row.run rowDes (result, intToRow rowIndex, maxCols, integerDatetimes)
|
||||
case rowResult of
|
||||
Left x -> writeIORef failureRef (Just (RowError rowIndex x))
|
||||
|
@ -8,6 +8,7 @@ module Hasql.Prelude
|
||||
bug,
|
||||
bottom,
|
||||
forMToZero_,
|
||||
forMFromZero_,
|
||||
strictCons,
|
||||
)
|
||||
where
|
||||
@ -122,6 +123,11 @@ forMToZero_ :: Applicative m => Int -> (Int -> m a) -> m ()
|
||||
forMToZero_ !startN f =
|
||||
($ pred startN) $ fix $ \loop !n -> if n >= 0 then f n *> loop (pred n) else pure ()
|
||||
|
||||
{-# INLINE forMFromZero_ #-}
|
||||
forMFromZero_ :: Applicative m => Int -> (Int -> m a) -> m ()
|
||||
forMFromZero_ !endN f =
|
||||
($ 0) $ fix $ \loop !n -> if n < endN then f n *> loop (succ n) else pure ()
|
||||
|
||||
{-# INLINE strictCons #-}
|
||||
strictCons :: a -> [a] -> [a]
|
||||
strictCons !a b =
|
||||
|
Loading…
Reference in New Issue
Block a user