git.iko.soy/typeable/attoparsec
on master help sign in
Move inlinePerformIO to a safer place
a02aa16Bryan O'Sullivan
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,
1+{-# LANGUAGE BangPatterns, OverloadedStrings, RecordWildCards #-}
2− RecordWildCards, MagicHash, UnboxedTuples #-}
3-- |
2-- |
4-- Module : Data.Attoparsec.ByteString.Internal
3-- Module : Data.Attoparsec.ByteString.Internal
5-- Copyright : Bryan O'Sullivan 2007-2014
4-- Copyright : Bryan O'Sullivan 2007-2014
@@ -69,6 +68,7 @@ module Data.Attoparsec.ByteString.Internal
69import Control.Applicative ((<|>), (<$>))
68import Control.Applicative ((<|>), (<$>))
70import Control.Monad (when)
69import Control.Monad (when)
71import Data.Attoparsec.ByteString.FastSet (charClass, memberWord8)
70import Data.Attoparsec.ByteString.FastSet (charClass, memberWord8)
71+import Data.Attoparsec.ByteString.Fhthagn (inlinePerformIO)
72import Data.Attoparsec.Combinator ((<?>))
72import Data.Attoparsec.Combinator ((<?>))
73import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
73import Data.Attoparsec.Internal.Types hiding (Parser, Failure, Success)
74import Data.Word (Word8)
74import Data.Word (Word8)
@@ -84,9 +84,6 @@ import qualified Data.ByteString.Internal as B
84import qualified Data.ByteString.Lazy as L
84import qualified Data.ByteString.Lazy as L
85import qualified Data.ByteString.Unsafe as B
85import qualified Data.ByteString.Unsafe as B
86
86
87−import GHC.Base (realWorld#)
88−import GHC.IO (IO(IO))
89−
90type Parser = T.Parser B.ByteString B.ByteString
87type Parser = T.Parser B.ByteString B.ByteString
91type Result = IResult B.ByteString B.ByteString
88type Result = IResult B.ByteString B.ByteString
92type Failure r = T.Failure B.ByteString B.ByteString r
89type 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
426 _ -> error "parseOnly: impossible error!"
423 _ -> error "parseOnly: impossible error!"
427{-# INLINE parseOnly #-}
424{-# INLINE parseOnly #-}
428
425
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−
437get :: Parser ByteString
426get :: Parser ByteString
438get = T.Parser $ \t pos more _lose succ ->
427get = T.Parser $ \t pos more _lose succ ->
439 succ t pos more (B.unsafeDrop (fromPos pos) t)
428 succ t pos more (B.unsafeDrop (fromPos pos) t)
attoparsec.cabal+1
@@ -63,6 +63,7 @@ library
63 Data.Attoparsec.Types
63 Data.Attoparsec.Types
64 Data.Attoparsec.Zepto
64 Data.Attoparsec.Zepto
65 other-modules: Data.Attoparsec.ByteString.FastSet
65 other-modules: Data.Attoparsec.ByteString.FastSet
66+ Data.Attoparsec.ByteString.Fhthagn
66 Data.Attoparsec.ByteString.Internal
67 Data.Attoparsec.ByteString.Internal
67 Data.Attoparsec.Internal
68 Data.Attoparsec.Internal
68 Data.Attoparsec.Internal.Types
69 Data.Attoparsec.Internal.Types