diff options
author | Mitchell Rosen <mitchellwrosen@gmail.com> | 2018-04-30 18:05:07 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-05-05 13:29:52 -0400 |
commit | 418881f7181cbfa31c44f0794db65bf00916bde2 (patch) | |
tree | 418b887e3896087fddcbf500fe4f9f15a25700d4 /libraries | |
parent | cb1ee7e10e50b11b4a24e56b425e8f3485d298d5 (diff) | |
download | haskell-418881f7181cbfa31c44f0794db65bf00916bde2.tar.gz |
Use unsafeInsertNew to create timers in TimerManager
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/Event/PSQ.hs | 19 | ||||
-rw-r--r-- | libraries/base/GHC/Event/TimerManager.hs | 4 |
2 files changed, 5 insertions, 18 deletions
diff --git a/libraries/base/GHC/Event/PSQ.hs b/libraries/base/GHC/Event/PSQ.hs index 07b8de614b..6e13839491 100644 --- a/libraries/base/GHC/Event/PSQ.hs +++ b/libraries/base/GHC/Event/PSQ.hs @@ -28,7 +28,7 @@ module GHC.Event.PSQ , singleton -- * Insertion - , insert + , unsafeInsertNew -- * Delete/Update , delete @@ -36,7 +36,6 @@ module GHC.Event.PSQ -- * Conversion , toList - , fromList -- * Min , findMin @@ -213,14 +212,7 @@ singleton = Tip -- Insertion ------------------------------------------------------------------------------ --- | /O(min(n,W))/ Insert a new key, priority and value into the queue. If the key --- is already present in the queue, the associated priority and value are --- replaced with the supplied priority and value. -insert :: Key -> Prio -> v -> IntPSQ v -> IntPSQ v -insert k p x t0 = unsafeInsertNew k p x (delete k t0) - --- | Internal function to insert a key that is *not* present in the priority --- queue. +-- | /O(min(n,W))/ Insert a new key that is *not* present in the priority queue. {-# INLINABLE unsafeInsertNew #-} unsafeInsertNew :: Key -> Prio -> v -> IntPSQ v -> IntPSQ v unsafeInsertNew k p x = go @@ -340,13 +332,6 @@ binShrinkR k p x m l r = Bin k p x m l r -- Lists ------------------------------------------------------------------------------ --- | /O(n*min(n,W))/ Build a queue from a list of (key, priority, value) tuples. --- If the list contains more than one priority and value for the same key, the --- last priority and value for the key is retained. -{-# INLINABLE fromList #-} -fromList :: [Elem v] -> IntPSQ v -fromList = foldr (\(E k p x) im -> insert k p x im) empty - -- | /O(n)/ Convert a queue to a list of (key, priority, value) tuples. The -- order of the list is not specified. toList :: IntPSQ v -> [Elem v] diff --git a/libraries/base/GHC/Event/TimerManager.hs b/libraries/base/GHC/Event/TimerManager.hs index 046f49e280..a28d361ba1 100644 --- a/libraries/base/GHC/Event/TimerManager.hs +++ b/libraries/base/GHC/Event/TimerManager.hs @@ -220,7 +220,9 @@ registerTimeout mgr us cb = do now <- getMonotonicTimeNSec let expTime = fromIntegral us * 1000 + now - editTimeouts mgr (Q.insert key expTime cb) + -- "unsafeInsertNew" is safe - the key must not exist in the PSQ. It + -- doesn't because we just generated it from a unique supply. + editTimeouts mgr (Q.unsafeInsertNew key expTime cb) return $ TK key -- | Unregister an active timeout. |