Skip to content

Commit

Permalink
Remove base 4.3.0 cpp directives
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Oct 10, 2020
1 parent 54ef6ed commit cfb50f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
19 changes: 0 additions & 19 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,7 @@ import System.IO.Error (mkIOError, illegalOperationErrorType)
import Data.Monoid (Monoid(..))
#endif

#if MIN_VERSION_base(4,3,0)
import System.IO (hGetBufSome)
#else
import System.IO (hWaitForInput, hIsEOF)
#endif

import Data.IORef
import GHC.IO.Handle.Internals
Expand Down Expand Up @@ -1930,22 +1926,7 @@ hGetNonBlocking h i
--
hGetSome :: Handle -> Int -> IO ByteString
hGetSome hh i
#if MIN_VERSION_base(4,3,0)
| i > 0 = createAndTrim i $ \p -> hGetBufSome hh p i
#else
| i > 0 = let
loop = do
s <- hGetNonBlocking hh i
if not (null s)
then return s
else do eof <- hIsEOF hh
if eof then return s
else hWaitForInput hh (-1) >> loop
-- for this to work correctly, the
-- Handle should be in binary mode
-- (see GHC ticket #3808)
in loop
#endif
| i == 0 = return empty
| otherwise = illegalBufferSize hh "hGetSome" i

Expand Down
24 changes: 4 additions & 20 deletions Data/ByteString/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ import GHC.Exts ( Int(I#), Int#, Ptr(Ptr), Addr#, Char(C#)
, byteArrayContents#
, unsafeCoerce#
#endif
#if MIN_VERSION_base(4,3,0)
, sizeofByteArray#
#endif
, indexWord8Array#, indexCharArray#
, writeWord8Array#, writeCharArray#
, unsafeFreezeByteArray# )
Expand Down Expand Up @@ -124,16 +122,6 @@ import Prelude ( Eq(..), Ord(..), Ordering(..), Read(..), Show(..)
-- more flexible and it supports a wide range of operations.
--
data ShortByteString = SBS ByteArray#
#if !(MIN_VERSION_base(4,3,0))
{-# UNPACK #-} !Int -- ^ Prior to ghc-7.0.x, 'ByteArray#'s reported
-- their length rounded up to the nearest word.
-- This means we have to store the true length
-- separately, wasting a word.
#define LEN(x) (x)
#else
#define _len /* empty */
#define LEN(x) /* empty */
#endif
deriving Typeable

-- The ByteArray# representation is always word sized and aligned but with a
Expand Down Expand Up @@ -199,11 +187,7 @@ empty = create 0 (\_ -> return ())

-- | /O(1)/ The length of a 'ShortByteString'.
length :: ShortByteString -> Int
#if MIN_VERSION_base(4,3,0)
length (SBS barr#) = I# (sizeofByteArray# barr#)
#else
length (SBS _ len) = len
#endif

-- | /O(1)/ Test whether a 'ShortByteString' is empty.
null :: ShortByteString -> Bool
Expand Down Expand Up @@ -248,15 +232,15 @@ indexError sbs i =
-- Internal utils

asBA :: ShortByteString -> BA
asBA (SBS ba# _len) = BA# ba#
asBA (SBS ba#) = BA# ba#

create :: Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create len fill =
runST (do
mba <- newByteArray len
fill mba
BA# ba# <- unsafeFreezeByteArray mba
return (SBS ba# LEN(len)))
return (SBS ba#)
{-# INLINE create #-}

------------------------------------------------------------------------
Expand All @@ -276,7 +260,7 @@ toShortIO (BS fptr len) = do
stToIO (copyAddrToByteArray ptr mba 0 len)
touchForeignPtr fptr
BA# ba# <- stToIO (unsafeFreezeByteArray mba)
return (SBS ba# LEN(len))
return (SBS ba#)


-- | /O(n)/. Convert a 'ShortByteString' into a 'ByteString'.
Expand Down Expand Up @@ -476,7 +460,7 @@ createFromPtr !ptr len =
mba <- newByteArray len
copyAddrToByteArray ptr mba 0 len
BA# ba# <- unsafeFreezeByteArray mba
return (SBS ba# LEN(len))
return (SBS ba#)


------------------------------------------------------------------------
Expand Down

0 comments on commit cfb50f8

Please sign in to comment.