diff options
author | doyougnu <jeffrey.young@iohk.io> | 2022-11-16 20:25:22 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-01 12:36:44 -0500 |
commit | 72cf4c5d74923d267dab2dc260af090609066b04 (patch) | |
tree | fce2f370db760c28ba351b6855bcfb530b0d7b7c | |
parent | d87f28d810b9c536ca4db7f363163e6d0dd6c93c (diff) | |
download | haskell-72cf4c5d74923d267dab2dc260af090609066b04.tar.gz |
FastString: SAT bucket_match
Metric Decrease:
MultiLayerModulesTH_OneShot
-rw-r--r-- | compiler/GHC/Data/FastString.hs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs index 1e0acae583..5b9baa5c82 100644 --- a/compiler/GHC/Data/FastString.hs +++ b/compiler/GHC/Data/FastString.hs @@ -465,8 +465,7 @@ mkFastStringWith mk_fs sbs = do FastStringTableSegment lock _ buckets# <- readIORef segmentRef let idx# = hashToIndex# buckets# hash# bucket <- IO $ readArray# buckets# idx# - res <- bucket_match bucket sbs - case res of + case bucket_match bucket sbs of Just found -> return found Nothing -> do -- The withMVar below is not dupable. It can lead to deadlock if it is @@ -485,8 +484,7 @@ mkFastStringWith mk_fs sbs = do FastStringTableSegment _ counter buckets# <- maybeResizeSegment segmentRef let idx# = hashToIndex# buckets# hash# bucket <- IO $ readArray# buckets# idx# - res <- bucket_match bucket sbs - case res of + case bucket_match bucket sbs of -- The FastString was added by another thread after previous read and -- before we acquired the write lock. Just found -> return found @@ -497,11 +495,12 @@ mkFastStringWith mk_fs sbs = do _ <- atomicFetchAddFastMut counter 1 return fs -bucket_match :: [FastString] -> ShortByteString -> IO (Maybe FastString) -bucket_match [] _ = return Nothing -bucket_match (fs@(FastString {fs_sbs=fs_sbs}) : ls) sbs - | fs_sbs == sbs = return (Just fs) - | otherwise = bucket_match ls sbs +bucket_match :: [FastString] -> ShortByteString -> Maybe FastString +bucket_match fs sbs = go fs + where go [] = Nothing + go (fs@(FastString {fs_sbs=fs_sbs}) : ls) + | fs_sbs == sbs = Just fs + | otherwise = go ls mkFastStringBytes :: Ptr Word8 -> Int -> FastString mkFastStringBytes !ptr !len = |