summaryrefslogtreecommitdiff
path: root/src-2.9/GF/Data/SharedString.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-20 11:47:44 +0000
commit31bf84122b21efb444aa8d055472e166ffb90783 (patch)
tree1f051909336f1534346bcccde8dda59beab02f64 /src-2.9/GF/Data/SharedString.hs
parent74f048dcf41de3540778de54dfa7541fa5b39c46 (diff)
moved all old source code to src-2.9 ; src will be for GF 3 development
Diffstat (limited to 'src-2.9/GF/Data/SharedString.hs')
-rw-r--r--src-2.9/GF/Data/SharedString.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src-2.9/GF/Data/SharedString.hs b/src-2.9/GF/Data/SharedString.hs
new file mode 100644
index 000000000..9d037b512
--- /dev/null
+++ b/src-2.9/GF/Data/SharedString.hs
@@ -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