mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-21 02:39:31 -06:00
moved all old source code to src-2.9 ; src will be for GF 3 development
This commit is contained in:
19
src-2.9/GF/Data/SharedString.hs
Normal file
19
src-2.9/GF/Data/SharedString.hs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
module GF.Data.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
|
||||
Reference in New Issue
Block a user