on main help sign in
Call checkfpBs inline
267e4c5Vladislav Zavialov
src/Data/TypeRep/OptimalVector.hs+12−7
@@ -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)
34+import Debug.Trace
34
35
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 =
90 let
91 let
91 !(I# len) = Unboxed.length fpAs
92 !(I# len) = Unboxed.length fpAs
92− ind = I# (binSearchHelp (-1#) len)
93+ checkfpBs :: Int# -> Maybe Int
94+ checkfpBs i =
95+ case i <# len of
96+ 0# -> Nothing
97+ _ ->
98+ if a /= Unboxed.unsafeIndex fpAs (I# i)
99+ then Nothing
100+ else if b == Unboxed.unsafeIndex fpBs (I# i)
101+ then Just (I# i)
102+ else checkfpBs (i +# 1#)
93 in
103 in
94− checkfpBs ind (I# len)
104+ inline (checkfpBs (binSearchHelp (-1#) len))
95 where
105 where
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
104
114
105− checkfpBs :: Int -> Int -> Maybe Int
106− checkfpBs i len
107− | i >= len || a /= Unboxed.unsafeIndex fpAs i = Nothing
108− | b == Unboxed.unsafeIndex fpBs i = Just i
109− | otherwise = checkfpBs (i + 1) len