summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexbiehl <alex.biehl@gmail.com>2017-03-23 20:33:20 +0100
committeralexbiehl <alex.biehl@gmail.com>2017-03-23 20:33:20 +0100
commit5748f7642e406ddf232fd49edf6366a3e4de8bf0 (patch)
tree7c50c4c134812bc27a0214f6a8aca36fc955af9b
parente0f1054ba3f27de9dcffdb9b493c88c265cba6d7 (diff)
downloadhaskell-5748f7642e406ddf232fd49edf6366a3e4de8bf0.tar.gz
Try out another hash for FastStrings as discussed in IRC
-rw-r--r--compiler/utils/FastString.hs23
1 files changed, 12 insertions, 11 deletions
diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs
index 8d1bbb5c67..b09467091d 100644
--- a/compiler/utils/FastString.hs
+++ b/compiler/utils/FastString.hs
@@ -102,6 +102,7 @@ import FastFunctions
import Panic
import Util
+import Data.Bits ((.&.))
import Control.DeepSeq
import Control.Monad
import Data.ByteString (ByteString)
@@ -129,8 +130,8 @@ import GHC.Conc.Sync (sharedCAF)
import GHC.Base ( unpackCString# )
-#define hASH_TBL_SIZE 4091
-#define hASH_TBL_SIZE_UNBOXED 4091#
+#define hASH_TBL_SIZE 4096
+#define hASH_TBL_SIZE_UNBOXED 4096#
fastStringToByteString :: FastString -> ByteString
@@ -453,16 +454,16 @@ cmpStringPrefix ptr1 ptr2 len =
do r <- memcmp ptr1 ptr2 len
return (r == 0)
+hashStr :: Ptr Word8 -> Int -> Int
+hashStr (Ptr a#) (I# len#) = loop 0# a# .&. (hASH_TBL_SIZE - 1)
+ where
+ !end = plusAddr# a# len#
-hashStr :: Ptr Word8 -> Int -> Int
- -- use the Addr to produce a hash value between 0 & m (inclusive)
-hashStr (Ptr a#) (I# len#) = loop 0# 0#
- where
- loop h n | isTrue# (n ==# len#) = I# h
- | otherwise = loop h2 (n +# 1#)
- where !c = ord# (indexCharOffAddr# a# n)
- !h2 = (c +# (h *# 128#)) `remInt#`
- hASH_TBL_SIZE#
+ loop h op | isTrue# (eqAddr# op end) = I# h
+ | otherwise = loop h' (plusAddr# op 1#)
+ where
+ !c = ord# (indexCharOffAddr# op 0#)
+ !h' = h *# 31# +# c
-- -----------------------------------------------------------------------------
-- Operations