Use HashTable to share strings in tokens when parsing GFC files.

This commit is contained in:
bringert
2004-12-06 16:02:08 +00:00
parent b637293072
commit 798cb37002
3 changed files with 156 additions and 7 deletions

View File

@@ -0,0 +1,18 @@
module SharedString (shareString) where
import Data.HashTable as H
import System.IO.Unsafe (unsafePerformIO)
{-# NOINLINE stringPool #-}
stringPool :: HashTable String String
stringPool = unsafePerformIO $ new (==) hashString
{-# NOINLINE shareString #-}
shareString :: String -> String
shareString s = unsafePerformIO $ do
mv <- H.lookup stringPool s
case mv of
Just s' -> return s'
Nothing -> do
H.insert stringPool s s
return s