From d55ed8d626b4670bb27f5985a87e8605345e6e9e Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Wed, 29 Jun 2022 13:37:09 +0200 Subject: [PATCH] withParams*: drop redundant call to 'length' by using 'withArrayLen' We encode various arrays of the same length through 'withArray'. Each of these computes the length, so we might as well take the length from one of these. --- src/Database/PostgreSQL/LibPQ.hsc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Database/PostgreSQL/LibPQ.hsc b/src/Database/PostgreSQL/LibPQ.hsc index 8699b56..0b5186e 100644 --- a/src/Database/PostgreSQL/LibPQ.hsc +++ b/src/Database/PostgreSQL/LibPQ.hsc @@ -754,15 +754,12 @@ withParams params action = withMany (maybeWith B.useAsCString) values $ \c_values -> withArray c_values $ \vs -> withArray c_lengths $ \ls -> - withArray formats $ \fs -> - action n ts vs ls fs + withArrayLen formats $ \n fs -> + action (intToCInt n) ts vs ls fs where AccumParams oids values c_lengths formats = foldr accum (AccumParams [] [] [] []) params - n :: CInt - !n = intToCInt $ length params - accum :: Maybe (Oid, B.ByteString, Format) -> AccumParams -> AccumParams accum Nothing ~(AccumParams a b c d) = AccumParams (invalidOid : a) (Nothing : b) (0 : c) (0 : d) @@ -790,15 +787,12 @@ withParamsPrepared params action = withMany (maybeWith B.useAsCString) values $ \c_values -> withArray c_values $ \vs -> withArray c_lengths $ \ls -> - withArray formats $ \fs -> - action n vs ls fs + withArrayLen formats $ \n fs -> + action (intToCInt n) vs ls fs where AccumPrepParams values c_lengths formats = foldr accum (AccumPrepParams [] [] []) params - n :: CInt - n = intToCInt $ length params - accum :: Maybe (B.ByteString ,Format) -> AccumPrepParams -> AccumPrepParams accum Nothing ~(AccumPrepParams a b c) = AccumPrepParams (Nothing : a) (0 : b) (0 : c)