git.iko.soy/typeable/attoparsec
on master help sign in
Merge pull request #81 from kvanberendonck/master

Use special unsigned tests to reduce branches for isDigit_w8, isSpace_w8

commitc8e3c269b706770ef2e7a37d68c3079ce59f0169 authorBryan O'Sullivan <bos@serpentine.com> dateTue 20 Jan 2015, 14:44 (12 years ago) parentaefe8f964445b0
1 file changed+5−2
Data/Attoparsec/ByteString/Char8.hs+5−2
Data/Attoparsec/ByteString/Char8.hs+5−2
@@ -239,7 +239,8 @@ isDigit c = c >= '0' && c <= '9'
239239
240240-- | A fast digit predicate.
241241isDigit_w8 :: Word8 -> Bool
242−isDigit_w8 w = w >= 48 && w <= 57
242+isDigit_w8 w | w - 48 <= 9 = True
243+ | otherwise = False
243244{-# INLINE isDigit_w8 #-}
244245
245246-- | Match any character.
@@ -276,7 +277,9 @@ isSpace c = (c == ' ') || ('\t' <= c && c <= '\r')
276277
277278-- | Fast 'Word8' predicate for matching ASCII space characters.
278279isSpace_w8 :: Word8 -> Bool
279−isSpace_w8 w = (w == 32) || (9 <= w && w <= 13)
280+isSpace_w8 w | w == 32 = True
281+ | w - 9 <= 4 = True
282+ | otherwise = False
280283{-# INLINE isSpace_w8 #-}
281284
282285