X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FFastString.lhs;h=5b9c7f934680cec8d36359772fc9defd50833a32;hb=f2eb50cc42d4ce9e27c2328016b1ddbc2abab04c;hp=637ef0cf72276b54ee38d49117734089a826e076;hpb=a5e533a6d23eed8a8f14314d54fd727b8023edf9;p=ghc-hetmet.git diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs index 637ef0c..5b9c7f9 100644 --- a/compiler/utils/FastString.lhs +++ b/compiler/utils/FastString.lhs @@ -78,11 +78,12 @@ import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) import System.IO ( hPutBuf ) import Data.Maybe ( isJust ) -import GHC.Arr ( STArray(..), newSTArray ) +import GHC.ST import GHC.IOBase ( IO(..) ) import GHC.Ptr ( Ptr(..) ) -#define hASH_TBL_SIZE 4091 +#define hASH_TBL_SIZE 4091 +#define hASH_TBL_SIZE_UNBOXED 4091# {-| @@ -129,15 +130,17 @@ instance Show FastString where cmpFS :: FastString -> FastString -> Ordering cmpFS (FastString u1 l1 _ buf1 _) (FastString u2 l2 _ buf2 _) = if u1 == u2 then EQ else - let l = if l1 <= l2 then l1 else l2 in - inlinePerformIO $ - withForeignPtr buf1 $ \p1 -> - withForeignPtr buf2 $ \p2 -> do - res <- memcmp p1 p2 l - return $ case compare res 0 of - LT -> LT - EQ -> compare l1 l2 - GT -> GT + case unsafeMemcmp buf1 buf2 (min l1 l2) `compare` 0 of + LT -> LT + EQ -> compare l1 l2 + GT -> GT + +unsafeMemcmp :: ForeignPtr a -> ForeignPtr b -> Int -> Int +unsafeMemcmp buf1 buf2 l = + inlinePerformIO $ + withForeignPtr buf1 $ \p1 -> + withForeignPtr buf2 $ \p2 -> + memcmp p1 p2 l #ifndef __HADDOCK__ foreign import ccall unsafe "ghc_memcmp" @@ -163,8 +166,10 @@ data FastStringTable = string_table :: IORef FastStringTable string_table = unsafePerformIO $ do - (STArray _ _ arr#) <- stToIO (newSTArray (0::Int,hASH_TBL_SIZE) []) - newIORef (FastStringTable 0 arr#) + tab <- IO $ \s1# -> case newArray# hASH_TBL_SIZE_UNBOXED [] s1# of + (# s2#, arr# #) -> + (# s2#, FastStringTable 0 arr# #) + newIORef tab lookupTbl :: FastStringTable -> Int -> IO [FastString] lookupTbl (FastStringTable _ arr#) (I# i#) =