Skip to content

Commit

Permalink
No reason to resort for unboxed manipulations in splitWith
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Sep 7, 2020
1 parent eee71e3 commit 066fbde
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash, UnboxedTuples,
NamedFieldPuns, BangPatterns #-}
{-# OPTIONS_HADDOCK prune #-}
#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Trustworthy #-}
Expand Down Expand Up @@ -281,7 +279,6 @@ import GHC.IO (unsafePerformIO, unsafeDupablePerformIO)
import Data.Char (ord)
import Foreign.Marshal.Utils (copyBytes)

import GHC.Prim (Word#)
import GHC.Base (build)
import GHC.Word hiding (Word8)

Expand Down Expand Up @@ -1123,12 +1120,9 @@ spanEnd p ps = splitAt (findFromEndUntil (not.p) ps) ps
-- > splitWith undefined "" == [] -- and not [""]
--
splitWith :: (Word8 -> Bool) -> ByteString -> [ByteString]
splitWith _pred (BS _ 0) = []
splitWith pred_ (BS fp len) = splitWith0 0 len fp
where pred# :: (Word# -> Bool)
pred# c# = pred_ (W8# c#)

splitWith0 !off' !len' !fp' =
splitWith _ (BS _ 0) = []
splitWith predicate (BS fp len) = splitWith0 0 len fp
where splitWith0 !off' !len' !fp' =
accursedUnutterablePerformIO $
withForeignPtr fp $ \p ->
splitLoop p 0 off' len' fp'
Expand All @@ -1143,7 +1137,7 @@ splitWith pred_ (BS fp len) = splitWith0 0 len fp
| idx' >= len' = return [BS (plusForeignPtr fp' off') idx']
| otherwise = do
w <- peekElemOff p (off'+idx')
if pred# (case w of W8# w# -> w#)
if predicate w
then return (BS (plusForeignPtr fp' off') idx' :
splitWith0 (off'+idx'+1) (len'-idx'-1) fp')
else go (idx'+1)
Expand Down

0 comments on commit 066fbde

Please sign in to comment.