Commits

Bryan O'Sullivan committed a498126

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.

  • Participants
  • Parent commits aa73332

Comments (0)

Files changed (1)

Data/Text/Search.hs

 import Data.Bits ((.|.), (.&.))
 import Data.Text.UnsafeShift (shiftL)
 
+data T = {-# UNPACK #-} !Word64 :* {-# UNPACK #-} !Int
+
 -- | /O(n+m)/ Find the offsets of all non-overlapping indices of
 -- @needle@ within @haystack@.  The offsets returned represent
 -- locations in the low-level array.
     hindex k = A.unsafeIndex harr (hoff+k)
     hindex' k | k == hlen  = 0
               | otherwise = A.unsafeIndex harr (hoff+k)
-    (mask :: Word64) :*: skip  = buildTable 0 0 (nlen-2)
     buildTable !i !msk !skp
-        | i >= nlast           = (msk .|. swizzle z) :*: skp
+        | i >= nlast           = (msk .|. swizzle z) :* skp
         | otherwise            = buildTable (i+1) (msk .|. swizzle c) skp'
         where c                = nindex i
               skp' | c == z    = nlen - i - 2
                     | c == z        = skip + 1
                     | otherwise     = 1
               nextInPattern         = mask .&. swizzle (hindex' (i+nlen)) == 0
+              !(mask :* skip)       = buildTable 0 0 (nlen-2)
     scanOne c = loop 0
         where loop !i | i >= hlen     = []
                       | hindex i == c = i : loop (i+1)