git.iko.soy/typeable/attoparsec
on master help sign in
Fix set-related bugs
e709c65Bryan O'Sullivan
src/Data/ParserCombinators/Attoparsec/FastSet.hs+5−3
@@ -30,6 +30,7 @@ module Data.ParserCombinators.Attoparsec.FastSet
30 ) where
30 ) where
31
31
32import Data.Bits ((.&.), (.|.), shiftR)
32import Data.Bits ((.&.), (.|.), shiftR)
33+import qualified Data.ByteString.Char8 as B8
33import qualified Data.ByteString as B
34import qualified Data.ByteString as B
34import qualified Data.ByteString.Internal as I
35import qualified Data.ByteString.Internal as I
35import qualified Data.ByteString.Unsafe as U
36import qualified Data.ByteString.Unsafe as U
@@ -41,7 +42,8 @@ data FastSet = Sorted { fromSet :: {-# UNPACK #-} !B.ByteString }
41 deriving (Eq, Ord)
42 deriving (Eq, Ord)
42
43
43instance Show FastSet where
44instance Show FastSet where
45+ show (Sorted s) = "FastSet Sorted " ++ show (B8.unpack s)
44− show _ = "FastSet"
46+ show (Table _) = "FastSet Table"
45
47
46-- | The lower bound on the size of a lookup table. We choose this to
48-- | The lower bound on the size of a lookup table. We choose this to
47-- balance table density against performance.
49-- balance table density against performance.
@@ -64,8 +66,8 @@ memberWord8 w (Sorted s) = search 0 (B.length s - 1)
64 | otherwise =
66 | otherwise =
65 let mid = (lo + hi) `div` 2
67 let mid = (lo + hi) `div` 2
66 in case compare w (U.unsafeIndex s mid) of
68 in case compare w (U.unsafeIndex s mid) of
67− GT -> search lo (mid - 1)
69+ GT -> search (mid + 1) hi
68− LT -> search (mid + 1) hi
70+ LT -> search lo (mid - 1)
69 _ -> True
71 _ -> True
70
72
71-- | Check the set for membership. Only works with 8-bit characters:
73-- | Check the set for membership. Only works with 8-bit characters: