From 7485f5cd8a7af9a85292475d2ac0a584a0fc3a86 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Mon, 13 Jul 2020 01:18:56 +0200 Subject: [PATCH] Remove custom unsafeShift{L,R} definitions (#281) With GHC < 8.2, the standard `unsafeShift{L,R}` definitions aren't inlined properly in larger unfoldings. This results in benchmark slowdowns on the order of 1 to 6%. --- Data/HashMap/Base.hs | 5 ++--- Data/HashMap/UnsafeShift.hs | 16 ---------------- unordered-containers.cabal | 1 - 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 Data/HashMap/UnsafeShift.hs diff --git a/Data/HashMap/Base.hs b/Data/HashMap/Base.hs index 007a71b1..395c5fd9 100644 --- a/Data/HashMap/Base.hs +++ b/Data/HashMap/Base.hs @@ -129,7 +129,7 @@ import Data.Semigroup (Semigroup((<>))) #endif import Control.DeepSeq (NFData(rnf)) import Control.Monad.ST (ST) -import Data.Bits ((.&.), (.|.), complement, popCount) +import Data.Bits ((.&.), (.|.), complement, popCount, unsafeShiftL, unsafeShiftR) import Data.Data hiding (Typeable) import qualified Data.Foldable as Foldable #if MIN_VERSION_base(4,10,0) @@ -144,7 +144,6 @@ import qualified Data.HashMap.Array as A import qualified Data.Hashable as H import Data.Hashable (Hashable) import Data.HashMap.Unsafe (runST) -import Data.HashMap.UnsafeShift (unsafeShiftL, unsafeShiftR) import Data.HashMap.List (isPermutationBy, unorderedCompare) import Data.Typeable (Typeable) @@ -2101,7 +2100,7 @@ bitsPerSubkey :: Int bitsPerSubkey = 4 maxChildren :: Int -maxChildren = fromIntegral $ 1 `unsafeShiftL` bitsPerSubkey +maxChildren = 1 `unsafeShiftL` bitsPerSubkey subkeyMask :: Bitmap subkeyMask = 1 `unsafeShiftL` bitsPerSubkey - 1 diff --git a/Data/HashMap/UnsafeShift.hs b/Data/HashMap/UnsafeShift.hs deleted file mode 100644 index 529ba504..00000000 --- a/Data/HashMap/UnsafeShift.hs +++ /dev/null @@ -1,16 +0,0 @@ -{-# LANGUAGE MagicHash #-} - -module Data.HashMap.UnsafeShift - ( unsafeShiftL - , unsafeShiftR - ) where - -import GHC.Exts (Word(W#), Int(I#), uncheckedShiftL#, uncheckedShiftRL#) - -unsafeShiftL :: Word -> Int -> Word -unsafeShiftL (W# x#) (I# i#) = W# (x# `uncheckedShiftL#` i#) -{-# INLINE unsafeShiftL #-} - -unsafeShiftR :: Word -> Int -> Word -unsafeShiftR (W# x#) (I# i#) = W# (x# `uncheckedShiftRL#` i#) -{-# INLINE unsafeShiftR #-} diff --git a/unordered-containers.cabal b/unordered-containers.cabal index c4646eb4..aec2a713 100644 --- a/unordered-containers.cabal +++ b/unordered-containers.cabal @@ -46,7 +46,6 @@ library Data.HashMap.Strict.Base Data.HashMap.List Data.HashMap.Unsafe - Data.HashMap.UnsafeShift Data.HashSet.Base build-depends: