Skip to content

Commit 325087f

Browse files
committed
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.
1 parent bc69f4b commit 325087f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Database/PostgreSQL/LibPQ.hsc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,11 @@ withParams params action =
756756
withMany (maybeWith B.useAsCString) values $ \c_values ->
757757
withArray c_values $ \vs ->
758758
withArray c_lengths $ \ls ->
759-
withArray formats $ \fs ->
760-
action n ts vs ls fs
759+
withArrayLen formats $ \n fs ->
760+
action (toEnum n) ts vs ls fs
761761
where
762762
(oids, values, c_lengths, formats) =
763763
foldl' accum ([],[],[],[]) $ reverse params
764-
!n = toEnum $ length params
765764

766765
accum (!a,!b,!c,!d) Nothing = ( invalidOid:a
767766
, Nothing:b
@@ -783,11 +782,10 @@ withParamsPrepared params action =
783782
withMany (maybeWith B.useAsCString) values $ \c_values ->
784783
withArray c_values $ \vs ->
785784
withArray c_lengths $ \ls ->
786-
withArray formats $ \fs ->
787-
action n vs ls fs
785+
withArrayLen formats $ \n fs ->
786+
action (toEnum n) vs ls fs
788787
where
789788
(values, c_lengths, formats) = foldl' accum ([],[],[]) $ reverse params
790-
!n = toEnum $ length params
791789

792790
accum (!a,!b,!c) Nothing = ( Nothing:a
793791
, 0:b

0 commit comments

Comments
 (0)