Skip to content

Commit 79b5484

Browse files
authored
Merge pull request #21 from arybczak/master
Fix space leak in System.Metrics.Label.set
2 parents 40ced1b + 70b28fa commit 79b5484

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

System/Metrics/Label.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module System.Metrics.Label
1212
, modify
1313
) where
1414

15-
import Data.IORef (IORef, atomicModifyIORef, newIORef, readIORef)
15+
import Data.IORef (IORef, atomicModifyIORef', atomicWriteIORef, newIORef, readIORef)
1616
import qualified Data.Text as T
1717
import Prelude hiding (read)
1818

@@ -29,11 +29,9 @@ read = readIORef . unC
2929

3030
-- | Set the label to the given value.
3131
set :: Label -> T.Text -> IO ()
32-
set (C ref) !i = atomicModifyIORef ref $ \ _ -> (i, ())
32+
set (C ref) !i = atomicWriteIORef ref i
3333

3434
-- | Set the label to the result of applying the given function to the
3535
-- value.
3636
modify :: (T.Text -> T.Text) -> Label -> IO ()
37-
modify f (C ref) = do
38-
!_ <- atomicModifyIORef ref $ \ i -> let i' = f i in (i', i')
39-
return ()
37+
modify f (C ref) = atomicModifyIORef' ref $ \i -> (f i, ())

0 commit comments

Comments
 (0)