diff options
| author | bjorn <bjorn@bringert.net> | 2008-10-02 13:23:54 +0000 |
|---|---|---|
| committer | bjorn <bjorn@bringert.net> | 2008-10-02 13:23:54 +0000 |
| commit | 86a30ef99213670b305934a4d0976d458db7db97 (patch) | |
| tree | 63c2fa245672020e11fe2ee0363f5c180c7bd6a8 /src/GF/Source/SharedString.hs | |
| parent | 8fb068df6a4a9971f6c045744a16b07a895a5519 (diff) | |
Converted GF/Source/*.hs to Unix line endings, to be able to see what happens when I regenerated the files.
Diffstat (limited to 'src/GF/Source/SharedString.hs')
| -rw-r--r-- | src/GF/Source/SharedString.hs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/GF/Source/SharedString.hs b/src/GF/Source/SharedString.hs index 732873fe6..358f70494 100644 --- a/src/GF/Source/SharedString.hs +++ b/src/GF/Source/SharedString.hs @@ -1,20 +1,20 @@ -module GF.Source.SharedString (shareString) where
-
-import Data.Map as M
-import Data.IORef
-import qualified Data.ByteString.Char8 as BS
-import System.IO.Unsafe (unsafePerformIO)
-
-{-# NOINLINE stringPoolRef #-}
-stringPoolRef :: IORef (M.Map BS.ByteString BS.ByteString)
-stringPoolRef = unsafePerformIO $ newIORef M.empty
-
-{-# NOINLINE shareString #-}
-shareString :: BS.ByteString -> BS.ByteString
-shareString s = unsafePerformIO $ do
- stringPool <- readIORef stringPoolRef
- case M.lookup s stringPool of
- Just s' -> return s'
- Nothing -> do let s' = BS.copy s
- writeIORef stringPoolRef $! M.insert s' s' stringPool
- return s'
+module GF.Source.SharedString (shareString) where + +import Data.Map as M +import Data.IORef +import qualified Data.ByteString.Char8 as BS +import System.IO.Unsafe (unsafePerformIO) + +{-# NOINLINE stringPoolRef #-} +stringPoolRef :: IORef (M.Map BS.ByteString BS.ByteString) +stringPoolRef = unsafePerformIO $ newIORef M.empty + +{-# NOINLINE shareString #-} +shareString :: BS.ByteString -> BS.ByteString +shareString s = unsafePerformIO $ do + stringPool <- readIORef stringPoolRef + case M.lookup s stringPool of + Just s' -> return s' + Nothing -> do let s' = BS.copy s + writeIORef stringPoolRef $! M.insert s' s' stringPool + return s' |
