git.iko.soy/typeable/attoparsec
on master help sign in
Move inlinePerformIO to a safer place
commita02aa16e8ca20173ffe9e4b04a73f57b7eb981d5 authorBryan O'Sullivan <bos@serpentine.com> dateMon 19 May 2014, 09:45 (12 years ago) parent977f221
3 files changed+21−13
Data/Attoparsec/ByteString/Fhthagn.hs+18 Data/Attoparsec/ByteString/Internal.hs+2−13 attoparsec.cabal+1
Data/Attoparsec/ByteString/Fhthagn.hsnew file+18
@@ -0,0 +1,18 @@
1+{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings,
2+ RecordWildCards, MagicHash, UnboxedTuples #-}
3+
4+module Data.Attoparsec.ByteString.Fhthagn
5+ (
6+ inlinePerformIO
7+ ) where
8+
9+import GHC.Base (realWorld#)
10+import GHC.IO (IO(IO))
11+
12+-- | Just like unsafePerformIO, but we inline it. Big performance gains as
13+-- it exposes lots of things to further inlining. /Very unsafe/. In
14+-- particular, you should do no memory allocation inside an
15+-- 'inlinePerformIO' block. On Hugs this is just @unsafePerformIO@.
16+inlinePerformIO :: IO a -> a
17+inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
18+{-# INLINE inlinePerformIO #-}
Data/Attoparsec/ByteString/Internal.hs+2−13
@@ -1,5 +1,4 @@
1−{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings,
2− RecordWildCards, MagicHash, UnboxedTuples #-}
1+{-# LANGUAGE BangPatterns, OverloadedStrings, RecordWildCards #-}
32-- |
43-- Module : Data.Attoparsec.ByteString.Internal
54-- Copyright : Bryan O'Sullivan 2007-2014
@@ -69,6 +68,7 @@ module Data.Attoparsec.ByteString.Internal
6968import Control.Applicative ((<|>), (<$>))
7069import Control.Monad (when)
7170import Data.Attoparsec.ByteString.FastSet (charClass, memberWord8)
71+import Data.Attoparsec.ByteString.Fhthagn (inlinePerformIO)
7272import Data.Attoparsec.Combinator ((<?>))
7373import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
7474import Data.Word (Word8)
@@ -84,9 +84,6 @@ import qualified Data.ByteString.Internal as B
8484import qualified Data.ByteString.Lazy as L
8585import qualified Data.ByteString.Unsafe as B
8686
87−import GHC.Base (realWorld#)
88−import GHC.IO (IO(IO))
89−
9087type Parser = T.Parser B.ByteString B.ByteString
9188type Result = IResult B.ByteString B.ByteString
9289type Failure r = T.Failure B.ByteString B.ByteString r
@@ -426,14 +423,6 @@ parseOnly m s = case T.runParser m s (Pos 0) Complete failK successK of
426423 _ -> error "parseOnly: impossible error!"
427424{-# INLINE parseOnly #-}
428425
429−-- | Just like unsafePerformIO, but we inline it. Big performance gains as
430−-- it exposes lots of things to further inlining. /Very unsafe/. In
431−-- particular, you should do no memory allocation inside an
432−-- 'inlinePerformIO' block. On Hugs this is just @unsafePerformIO@.
433−inlinePerformIO :: IO a -> a
434−inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
435−{-# INLINE inlinePerformIO #-}
436−
437426get :: Parser ByteString
438427get = T.Parser $ \t pos more _lose succ ->
439428 succ t pos more (B.unsafeDrop (fromPos pos) t)
attoparsec.cabal+1
@@ -63,6 +63,7 @@ library
6363 Data.Attoparsec.Types
6464 Data.Attoparsec.Zepto
6565 other-modules: Data.Attoparsec.ByteString.FastSet
66+ Data.Attoparsec.ByteString.Fhthagn
6667 Data.Attoparsec.ByteString.Internal
6768 Data.Attoparsec.Internal
6869 Data.Attoparsec.Internal.Types