Skip to content
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

Remove internal uses of withForeignPtr #536

Merged
merged 14 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
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
234 changes: 115 additions & 119 deletions Data/ByteString.hs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Data/ByteString/Builder/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ import Data.Semigroup (Semigroup((<>)))
#endif

import qualified Data.ByteString as S
import qualified Data.ByteString.Internal as S
import qualified Data.ByteString.Internal.Type as S
import qualified Data.ByteString.Lazy.Internal as L
import qualified Data.ByteString.Short.Internal as Sh

Expand Down Expand Up @@ -1099,8 +1099,8 @@ buildStepToCIOS (AllocationStrategy nextBuffer bufSize trim) =
wrapChunk !op' mkCIOS
| chunkSize == 0 = mkCIOS True
| trim chunkSize size = do
bs <- S.create chunkSize $ \pbuf' ->
copyBytes pbuf' pbuf chunkSize
bs <- S.createFp chunkSize $ \fpbuf' ->
S.memcpyFp fpbuf' fpbuf chunkSize
-- FIXME: We could reuse the trimmed buffer here.
return $ Yield1 bs (mkCIOS False)
| otherwise =
Expand Down
12 changes: 6 additions & 6 deletions Data/ByteString/Char8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ import Data.ByteString (null,length,tail,init,append
,useAsCString,useAsCStringLen
)

import Data.ByteString.Internal
import Data.ByteString.Internal.Type
import Data.ByteString.ReadInt
import Data.ByteString.ReadNat

Expand Down Expand Up @@ -975,11 +975,11 @@ unlines = \li -> let
(+!) = checkedAdd "Char8.unlines"

go [] _ = pure ()
go (BS srcFP len : srcs) dest = do
unsafeWithForeignPtr srcFP $ \src -> memcpy dest src len
pokeElemOff dest len (c2w '\n')
go srcs $ dest `plusPtr` (len + 1)
in unsafeCreate totLen (go li)
go (BS src len : srcs) dest = do
memcpyFp dest src len
pokeFpByteOff dest len (c2w '\n')
go srcs $ dest `plusForeignPtr` (len + 1)
in unsafeCreateFp totLen (go li)

-- | 'words' breaks a ByteString up into a list of words, which
-- were delimited by Chars representing white space.
Expand Down
Loading