further optimization by unpacking the ByteString in Ident

This commit is contained in:
kr.angelov
2008-05-21 19:51:52 +00:00
parent 8a595fc51f
commit bc2e5bfc4c

View File

@@ -29,13 +29,13 @@ import qualified Data.ByteString.Char8 as BS
-- | the constructors labelled /INTERNAL/ are -- | the constructors labelled /INTERNAL/ are
-- internal representation never returned by the parser -- internal representation never returned by the parser
data Ident = data Ident =
IC !BS.ByteString -- ^ raw identifier after parsing, resolved in Rename IC {-# UNPACK #-} !BS.ByteString -- ^ raw identifier after parsing, resolved in Rename
| IW -- ^ wildcard | IW -- ^ wildcard
-- --
-- below this constructor: internal representation never returned by the parser -- below this constructor: internal representation never returned by the parser
| IV !BS.ByteString Int -- ^ /INTERNAL/ variable | IV {-# UNPACK #-} !BS.ByteString {-# UNPACK #-} !Int -- ^ /INTERNAL/ variable
| IA !BS.ByteString Int -- ^ /INTERNAL/ argument of cat at position | IA {-# UNPACK #-} !BS.ByteString {-# UNPACK #-} !Int -- ^ /INTERNAL/ argument of cat at position
| IAV !BS.ByteString Int Int -- ^ /INTERNAL/ argument of cat with bindings at position | IAV {-# UNPACK #-} !BS.ByteString {-# UNPACK #-} !Int {-# UNPACK #-} !Int -- ^ /INTERNAL/ argument of cat with bindings at position
-- --
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
@@ -46,7 +46,7 @@ ident2bs i = case i of
IV s n -> BS.append s (BS.pack ('_':show n)) IV s n -> BS.append s (BS.pack ('_':show n))
IA s j -> BS.append s (BS.pack ('_':show j)) IA s j -> BS.append s (BS.pack ('_':show j))
IAV s b j -> BS.append s (BS.pack ('_':show b ++ '_':show j)) IAV s b j -> BS.append s (BS.pack ('_':show b ++ '_':show j))
IW -> BS.singleton '_' IW -> BS.pack "_"
prIdent :: Ident -> String prIdent :: Ident -> String
prIdent i = BS.unpack $! ident2bs i prIdent i = BS.unpack $! ident2bs i
@@ -73,7 +73,7 @@ varStr = identA (BS.pack "str") 0
-- | refreshing variables -- | refreshing variables
varX :: Int -> Ident varX :: Int -> Ident
varX = identV (BS.singleton 'x') varX = identV (BS.pack "x")
isWildIdent :: Ident -> Bool isWildIdent :: Ident -> Bool
isWildIdent x = case x of isWildIdent x = case x of