Bryan O'Sullivan avatar Bryan O'Sullivan committed 9c2929e

Speed up character class membership check.

Comments (0)

Files changed (2)

bytestringparser.cabal

 name:            bytestringparser
-version:         0.2
+version:         0.2.1
 license:         BSD3
 license-file:    LICENSE
 category:        Text, Parsing
 
   extensions:      CPP
   exposed-modules: Text.ParserCombinators.ByteStringParser
+                   Text.ParserCombinators.ByteStringParser.FastSet
   hs-source-dirs:  src
   ghc-options:     -O2 -Wall -Werror

src/Text/ParserCombinators/ByteStringParser.hs

 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Text.ParserCombinators.ByteStringParser
--- Copyright   :  (c) Daan Leijen 1999-2001, Jeremy Shaw 2006, Bryan O'Sullivan 2007
--- License     :  BSD-style (see the file libraries/parsec/LICENSE)
+-- Copyright   :  Daan Leijen 1999-2001, Jeremy Shaw 2006, Bryan O'Sullivan 2007-2008
+-- License     :  BSD3
 -- 
 -- Maintainer  :  bos@serpentine.com
 -- Stability   :  experimental
 import qualified Data.ByteString.Lazy.Internal as LB
 import Data.Char (isDigit, isLetter, isSpace, toLower)
 import Data.Int (Int64)
-import qualified Data.Set as S
+import Text.ParserCombinators.ByteStringParser.FastSet (FastSet, member, set)
 import Prelude hiding (takeWhile)
 
 type ParseError = String
 notChar c = satisfy (/= c) <?> "not " ++ [c]
 {-# INLINE notChar #-}
 
-charClass :: String -> S.Set Char
-charClass s = S.fromList (go s)
+charClass :: String -> FastSet
+charClass = set . SB.pack . go
     where go (a:'-':b:xs) = [a..b] ++ go xs
           go (x:xs) = x : go xs
           go _ = ""
 
 inClass :: String -> Char -> Bool
-inClass s = (`S.member` set)
-    where set = charClass s
+inClass s = (`member` myset)
+    where myset = charClass s
+{-# INLINE inClass #-}
 
 notInClass :: String -> Char -> Bool
-notInClass s = (`S.notMember` set)
-    where set = charClass s
+notInClass s = not . inClass s
+{-# INLINE notInClass #-}
 
 sepBy :: Parser a -> Parser s -> Parser [a]
 sepBy p s = liftM2 (:) p ((s >> sepBy1 p s) <|> return []) <|> return []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.