git.iko.soy/typeable/postgresql-simple
on master help sign in
Avoid buffer copies when not dealing with string types
commit44f1956b72626852355fc736e183f73e838b4dbb authorLeon P Smith <leon@melding-monads.com> dateFri 30 Dec 2011, 13:39 (15 years ago) parentaa44873
2 files changed+3−3
src/Database/PostgreSQL/Simple.hs+1−1 src/Database/PostgreSQL/Simple/Result.hs+2−2
src/Database/PostgreSQL/Simple.hs+1−1
@@ -387,7 +387,7 @@ finishQuery conn q result = do
387387 return Field{..}
388388 nrows <- PQ.ntuples result
389389 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)
391391 case convertResults fields values of
392392 Left err -> throwIO err
393393 Right a -> return a
src/Database/PostgreSQL/Simple/Result.hs+2−2
@@ -142,7 +142,7 @@ unBinary (Binary x) = x
142142instance Result SB.ByteString where
143143 convert f dat = if typeOid f == builtin2oid Bytea
144144 then unBinary <$> convert f dat
145− else doConvert f okText' pure dat
145+ else doConvert f okText' (pure . B.copy) dat
146146
147147instance Result PQ.Oid where
148148 convert f dat = PQ.Oid <$> atto (mkCompat Oid) decimal f dat
@@ -159,7 +159,7 @@ unescapeBytea f str = case unsafePerformIO (PQ.unescapeBytea str) of
159159instance Result (Binary SB.ByteString) where
160160 convert f dat = case format f of
161161 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
163163
164164instance Result (Binary LB.ByteString) where
165165 convert f dat = Binary . LB.fromChunks . (:[]) . unBinary <$> convert f dat