Skip to content

withParams*: drop redundant call to 'length' by using 'withArrayLen' #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/Database/PostgreSQL/LibPQ.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down