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 dependency on run-st library #33

Merged
merged 1 commit into from
Feb 26, 2024
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
1 change: 0 additions & 1 deletion bytesmith.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ library
, contiguous >=0.6 && <0.7
, natural-arithmetic >=0.1.3
, primitive >=0.7 && <0.10
, run-st >=0.1 && <0.2
, text-short >=0.1.3 && <0.2
, wide-word >=0.1.0.9 && <0.2

Expand Down
17 changes: 17 additions & 0 deletions sample/TakeLetter.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# language MagicHash #-}

-- Build with:
-- ghc -fforce-recomp -O2 -ddump-simpl -dsuppress-all -ddump-to-file sample/TakeLetter.hs
-- to examine GHC optimizations.
module TakeLetter
( takeLetter
) where

import Data.Bytes.Parser (Parser)
import Data.Text.Short (ShortText)
import Data.Bytes.Parser.Ascii (takeShortWhile)
import GHC.Exts

takeLetter :: Parser e s ShortText
{-# noinline takeLetter #-}
takeLetter = takeShortWhile (== 'A')
6 changes: 3 additions & 3 deletions src/Data/Bytes/Parser/Ascii.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Data.Bytes.Parser.Ascii

import Prelude hiding (any, fail, length, takeWhile)

import Control.Monad.ST.Run (runByteArrayST)
import Control.Monad.ST (runST)
import Data.Bits (clearBit)
import Data.Bytes.Parser.Internal (Parser (..), Result (..), Result#, indexLatinCharArray, uneffectful, uneffectful#, upcastUnitSuccess)
import Data.Bytes.Types (Bytes (..))
Expand Down Expand Up @@ -115,7 +115,7 @@ takeShortWhile p = do
end <- Unsafe.cursor
src <- Unsafe.expose
let len = end - start
!r = runByteArrayST $ do
!r = runST $ do
marr <- PM.newByteArray len
PM.copyByteArray marr 0 src start len
PM.unsafeFreezeByteArray marr
Expand All @@ -136,7 +136,7 @@ shortTrailedBy e !c = do
end <- Unsafe.cursor
src <- Unsafe.expose
let len = end - start - 1
!r = runByteArrayST $ do
!r = runST $ do
marr <- PM.newByteArray len
PM.copyByteArray marr 0 src start len
PM.unsafeFreezeByteArray marr
Expand Down
12 changes: 6 additions & 6 deletions src/Data/Bytes/Parser/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Data.Bytes.Parser.Internal
import Prelude hiding (any, fail, length, takeWhile)

import Control.Applicative (Alternative)
import Control.Monad.ST.Run (runByteArrayST)
import Control.Monad.ST (runST)
import Data.Bytes.Types (Bytes (..))
import Data.Kind (Type)
import Data.Primitive (ByteArray (ByteArray))
Expand Down Expand Up @@ -169,7 +169,7 @@ upcastUnitSuccess :: (# Int#, Int# #) -> Result# e ()
upcastUnitSuccess (# b, c #) = (# | (# (), b, c #) #)

swapArray16 :: Bytes -> ByteArray
swapArray16 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray16 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -184,7 +184,7 @@ swapArray16 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray32 :: Bytes -> ByteArray
swapArray32 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray32 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -203,7 +203,7 @@ swapArray32 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray64 :: Bytes -> ByteArray
swapArray64 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray64 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -230,7 +230,7 @@ swapArray64 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray128 :: Bytes -> ByteArray
swapArray128 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray128 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand Down Expand Up @@ -273,7 +273,7 @@ swapArray128 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray256 :: Bytes -> ByteArray
swapArray256 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray256 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand Down
Loading