on master help sign in
Ensure that GHC's CPR optimization fires.

Prior to this change, we definitely allocated the result on the heap when building the little faux-bloom-filter.

commit563716476d368618f519932c626f058d7e20496e authorBryan O'Sullivan <bos@serpentine.com> dateMon 13 Aug 2012, 10:08 (14 years ago) parent2256f5b
1 file changed+4−2
Data/Text/Search.hs+4−2
Data/Text/Search.hs+4−2
@@ -39,6 +39,8 @@ import Data.Text.Fusion.Internal (PairS(..))
3939import Data.Bits ((.|.), (.&.))
4040import Data.Text.UnsafeShift (shiftL)
4141
42+data T = {-# UNPACK #-} !Word64 :* {-# UNPACK #-} !Int
43+
4244-- | /O(n+m)/ Find the offsets of all non-overlapping indices of
4345-- @needle@ within @haystack@. The offsets returned represent
4446-- locations in the low-level array.
@@ -60,9 +62,8 @@ indices _needle@(Text narr noff nlen) _haystack@(Text harr hoff hlen)
6062 hindex k = A.unsafeIndex harr (hoff+k)
6163 hindex' k | k == hlen = 0
6264 | otherwise = A.unsafeIndex harr (hoff+k)
63− (mask :: Word64) :*: skip = buildTable 0 0 (nlen-2)
6465 buildTable !i !msk !skp
65− | i >= nlast = (msk .|. swizzle z) :*: skp
66+ | i >= nlast = (msk .|. swizzle z) :* skp
6667 | otherwise = buildTable (i+1) (msk .|. swizzle c) skp'
6768 where c = nindex i
6869 skp' | c == z = nlen - i - 2
@@ -81,6 +82,7 @@ indices _needle@(Text narr noff nlen) _haystack@(Text harr hoff hlen)
8182 | c == z = skip + 1
8283 | otherwise = 1
8384 nextInPattern = mask .&. swizzle (hindex' (i+nlen)) == 0
85+ !(mask :* skip) = buildTable 0 0 (nlen-2)
8486 scanOne c = loop 0
8587 where loop !i | i >= hlen = []
8688 | hindex i == c = i : loop (i+1)