mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-12 14:29:31 -06:00
20 lines
479 B
Haskell
20 lines
479 B
Haskell
|
|
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
|