@@ -25,20 +25,16 @@ import Control.DeepSeq
25
25
import qualified Data.Aeson as A
26
26
import Data.Binary (Binary , Get , put , get )
27
27
import Data.Hashable
28
- import qualified Data.HashMap.Strict as HM
29
- import Data.IORef (atomicModifyIORef' , newIORef )
30
28
import Data.List (stripPrefix )
31
29
import Data.String (IsString , fromString )
32
30
import Data.Text (Text )
33
31
import qualified Data.Text as T
34
- import Data.Tuple (swap )
35
32
import GHC.Generics
36
33
import Network.URI hiding (authority )
37
34
import qualified System.FilePath as FP
38
35
import qualified System.FilePath.Posix as FPP
39
36
import qualified System.FilePath.Windows as FPW
40
37
import qualified System.Info
41
- import System.IO.Unsafe (unsafePerformIO )
42
38
43
39
newtype Uri = Uri { getUri :: Text }
44
40
deriving (Eq ,Ord ,Read ,Show ,Generic ,A.FromJSON ,A.ToJSON ,Hashable ,A.ToJSONKey ,A.FromJSONKey )
@@ -175,7 +171,7 @@ instance Binary NormalizedFilePath where
175
171
176
172
-- | A smart constructor that performs UTF-8 encoding and hash consing
177
173
normalizedFilePath :: NormalizedUri -> FilePath -> NormalizedFilePath
178
- normalizedFilePath nuri nfp = intern $ NormalizedFilePath nuri nfp
174
+ normalizedFilePath nuri nfp = NormalizedFilePath nuri nfp
179
175
180
176
-- | Internal helper that takes a file path that is assumed to
181
177
-- already be normalized to a URI. It is up to the caller
@@ -211,19 +207,4 @@ normalizedFilePathToUri (NormalizedFilePath uri _) = uri
211
207
212
208
uriToNormalizedFilePath :: NormalizedUri -> Maybe NormalizedFilePath
213
209
uriToNormalizedFilePath nuri = fmap (normalizedFilePath nuri) mbFilePath
214
- where mbFilePath = platformAwareUriToFilePath System.Info. os (fromNormalizedUri nuri)
215
-
216
- ---------------------------------------------------------------------------
217
- -- Unsafe hashcons of NFP
218
- internIO :: (Eq a , Hashable a ) => IO (a -> IO a )
219
- internIO = do
220
- tableRef <- newIORef mempty
221
- let f x = atomicModifyIORef' tableRef $ swap . flip HM. alterF x (\ case
222
- Just res -> (res, Just res)
223
- Nothing -> (x, Just x)
224
- )
225
- return f
226
-
227
- {-# NOINLINE intern #-}
228
- intern :: NormalizedFilePath -> NormalizedFilePath
229
- intern = let f = unsafePerformIO internIO in \ x -> unsafePerformIO (f x)
210
+ where mbFilePath = platformAwareUriToFilePath System.Info. os (fromNormalizedUri nuri)
0 commit comments