git.iko.soy/typeable/attoparsec
on master help sign in
Made Data.Attoparsec.Char8.isChar faster, added isChar_w8, and added benchmarks
commit6900aff9dd1fbc93789249209f337b3ff735f981 authorwren ng thornton <wren@community.haskell.org> dateSun 10 Oct 2010, 20:52 (16 years ago) parent5c0dca5
1 file changed+11−5
Data/Attoparsec/Char8.hs+11−5
Data/Attoparsec/Char8.hs+11−5
@@ -49,6 +49,7 @@ module Data.Attoparsec.Char8
4949 , isAlpha_iso8859_15
5050 , isAlpha_ascii
5151 , isSpace
52+ , isSpace_w8
5253
5354 -- *** Character classes
5455 , inClass
@@ -188,18 +189,23 @@ anyChar :: Parser Char
188189anyChar = satisfy $ const True
189190{-# INLINE anyChar #-}
190191
191−-- | Fast predicate for matching a space character.
192+-- | Fast predicate for matching ASCII space characters.
192193--
193194-- /Note/: This predicate only gives correct answers for the ASCII
194195-- encoding. For instance, it does not recognise U+00A0 (non-breaking
195196-- space) as a space character, even though it is a valid ISO-8859-15
196−-- byte.
197+-- byte. For a Unicode-aware and only slightly slower predicate,
198+-- use 'Data.Char.isSpace'
197199isSpace :: Char -> Bool
198−isSpace c = c `B.elem` spaces
199− where spaces = B.pack " \n\r\t\v\f"
200− {-# NOINLINE spaces #-}
200+isSpace c = (c == ' ') || ('\t' <= c && c <= '\r')
201201{-# INLINE isSpace #-}
202202
203+-- | Fast 'Word8' predicate for matching ASCII space characters.
204+isSpace_w8 :: Word8 -> Bool
205+isSpace_w8 w = (w == 32) || (9 <= w && w <= 13)
206+{-# INLINE isSpace_w8 #-}
207+
208+
203209-- | Parse a space character.
204210--
205211-- /Note/: This parser only gives correct answers for the ASCII