@@ -31,6 +31,7 @@ import GHC.Base hiding (empty)
31import GHC.Exts (sortWith)
31import GHC.Exts (sortWith)
32import GHC.Fingerprint (Fingerprint (..))
32import GHC.Fingerprint (Fingerprint (..))
33import Unsafe.Coerce (unsafeCoerce)
33import Unsafe.Coerce (unsafeCoerce)
35import qualified Data.Vector as V
36import qualified Data.Vector as V
36import qualified Data.Vector.Unboxed as Unboxed
37import qualified Data.Vector.Unboxed as Unboxed
@@ -89,9 +90,18 @@ binarySearch :: Fingerprint -> Unboxed.Vector Word64 -> Unboxed.Vector Word64 ->
89binarySearch (Fingerprint a b) fpAs fpBs =
90binarySearch (Fingerprint a b) fpAs fpBs =
91 !(I# len) = Unboxed.length fpAs
92 !(I# len) = Unboxed.length fpAs
92− ind = I# (binSearchHelp (-1#) len)
93+ checkfpBs :: Int# -> Maybe Int
98+ if a /= Unboxed.unsafeIndex fpAs (I# i)
100+ else if b == Unboxed.unsafeIndex fpBs (I# i)
102+ else checkfpBs (i +# 1#)
94− checkfpBs ind (I# len)
104+ inline (checkfpBs (binSearchHelp (-1#) len))
96 binSearchHelp :: Int# -> Int# -> Int#
106 binSearchHelp :: Int# -> Int# -> Int#
97 binSearchHelp l r = case l <# (r -# 1#) of
107 binSearchHelp l r = case l <# (r -# 1#) of
@@ -102,8 +112,3 @@ binarySearch (Fingerprint a b) fpAs fpBs =
102 then binSearchHelp m r
112 then binSearchHelp m r
103 else binSearchHelp l m
113 else binSearchHelp l m
105− checkfpBs :: Int -> Int -> Maybe Int
107− | i >= len || a /= Unboxed.unsafeIndex fpAs i = Nothing
108− | b == Unboxed.unsafeIndex fpBs i = Just i
109− | otherwise = checkfpBs (i + 1) len