git.iko.soy/typeable/postgresql-simple
on master help sign in
Avoid buffer copies when not dealing with string types
44f1956Leon P Smith
src/Database/PostgreSQL/Simple.hs+1−1
@@ -387,7 +387,7 @@ finishQuery conn q result = do
387 return Field{..}
387 return Field{..}
388 nrows <- PQ.ntuples result
388 nrows <- PQ.ntuples result
389 forM' 0 (nrows-1) $ \row -> do
389 forM' 0 (nrows-1) $ \row -> do
390− values <- forM' 0 (ncols-1) (\col -> PQ.getvalue' result row col)
390+ values <- forM' 0 (ncols-1) (\col -> PQ.getvalue result row col)
391 case convertResults fields values of
391 case convertResults fields values of
392 Left err -> throwIO err
392 Left err -> throwIO err
393 Right a -> return a
393 Right a -> return a
src/Database/PostgreSQL/Simple/Result.hs+2−2
@@ -142,7 +142,7 @@ unBinary (Binary x) = x
142instance Result SB.ByteString where
142instance Result SB.ByteString where
143 convert f dat = if typeOid f == builtin2oid Bytea
143 convert f dat = if typeOid f == builtin2oid Bytea
144 then unBinary <$> convert f dat
144 then unBinary <$> convert f dat
145− else doConvert f okText' pure dat
145+ else doConvert f okText' (pure . B.copy) dat
146
146
147instance Result PQ.Oid where
147instance Result PQ.Oid where
148 convert f dat = PQ.Oid <$> atto (mkCompat Oid) decimal f dat
148 convert f dat = PQ.Oid <$> atto (mkCompat Oid) decimal f dat
@@ -159,7 +159,7 @@ unescapeBytea f str = case unsafePerformIO (PQ.unescapeBytea str) of
159instance Result (Binary SB.ByteString) where
159instance Result (Binary SB.ByteString) where
160 convert f dat = case format f of
160 convert f dat = case format f of
161 PQ.Text -> doConvert f okBinary (unescapeBytea f) dat
161 PQ.Text -> doConvert f okBinary (unescapeBytea f) dat
162− PQ.Binary -> doConvert f okBinary (pure . Binary) dat
162+ PQ.Binary -> doConvert f okBinary (pure . Binary . B.copy) dat
163
163
164instance Result (Binary LB.ByteString) where
164instance Result (Binary LB.ByteString) where
165 convert f dat = Binary . LB.fromChunks . (:[]) . unBinary <$> convert f dat
165 convert f dat = Binary . LB.fromChunks . (:[]) . unBinary <$> convert f dat