git.iko.soy/typeable/attoparsec
on master help sign in
Speed up character class membership check.
commit616165a7a05a0c79117ca9ef1ab9987b5dae46a6 authorBryan O'Sullivan <bos@serpentine.com> dateFri 25 Jan 2008, 15:32 (19 years ago) parent8454580
2 files changed+12−10
bytestringparser.cabal+2−1 src/Text/ParserCombinators/ByteStringParser.hs+10−9
bytestringparser.cabal+2−1
@@ -1,5 +1,5 @@
11name: bytestringparser
2−version: 0.2
2+version: 0.2.1
33license: BSD3
44license-file: LICENSE
55category: Text, Parsing
@@ -27,5 +27,6 @@ library
2727
2828 extensions: CPP
2929 exposed-modules: Text.ParserCombinators.ByteStringParser
30+ Text.ParserCombinators.ByteStringParser.FastSet
3031 hs-source-dirs: src
3132 ghc-options: -O2 -Wall -Werror
src/Text/ParserCombinators/ByteStringParser.hs+10−9
@@ -1,8 +1,8 @@
11-----------------------------------------------------------------------------
22-- |
33-- Module : Text.ParserCombinators.ByteStringParser
4−-- Copyright : (c) Daan Leijen 1999-2001, Jeremy Shaw 2006, Bryan O'Sullivan 2007
5−-- License : BSD-style (see the file libraries/parsec/LICENSE)
4+-- Copyright : Daan Leijen 1999-2001, Jeremy Shaw 2006, Bryan O'Sullivan 2007-2008
5+-- License : BSD3
66--
77-- Maintainer : bos@serpentine.com
88-- Stability : experimental
@@ -75,7 +75,7 @@ import qualified Data.ByteString.Lazy.Char8 as LB
7575import qualified Data.ByteString.Lazy.Internal as LB
7676import Data.Char (isDigit, isLetter, isSpace, toLower)
7777import Data.Int (Int64)
78−import qualified Data.Set as S
78+import Text.ParserCombinators.ByteStringParser.FastSet (FastSet, member, set)
7979import Prelude hiding (takeWhile)
8080
8181type ParseError = String
@@ -209,19 +209,20 @@ notChar :: Char -> Parser Char
209209notChar c = satisfy (/= c) <?> "not " ++ [c]
210210{-# INLINE notChar #-}
211211
212−charClass :: String -> S.Set Char
213−charClass s = S.fromList (go s)
212+charClass :: String -> FastSet
213+charClass = set . SB.pack . go
214214 where go (a:'-':b:xs) = [a..b] ++ go xs
215215 go (x:xs) = x : go xs
216216 go _ = ""
217217
218218inClass :: String -> Char -> Bool
219−inClass s = (`S.member` set)
220− where set = charClass s
219+inClass s = (`member` myset)
220+ where myset = charClass s
221+{-# INLINE inClass #-}
221222
222223notInClass :: String -> Char -> Bool
223−notInClass s = (`S.notMember` set)
224− where set = charClass s
224+notInClass s = not . inClass s
225+{-# INLINE notInClass #-}
225226
226227sepBy :: Parser a -> Parser s -> Parser [a]
227228sepBy p s = liftM2 (:) p ((s >> sepBy1 p s) <|> return []) <|> return []