Skip to content

Commit aadd360

Browse files
authored
Merge pull request #222 from input-output-hk/amesgen/tryReadTBQueueDefault
Minor tweaks to `tryReadTBQueueDefault`
2 parents 4f5a4cd + 3a2d2e1 commit aadd360

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

io-classes/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Revsion history of io-classes
22

3+
### next version
4+
5+
### Breaking changes
6+
7+
### Non-breaking changes
8+
9+
* Improved performance of `tryReadTBQueueDefault`.
10+
311
### 1.8.0.1
412

513
* Added support for `ghc-9.2`.

io-classes/src/Control/Monad/Class/MonadSTM/Internal.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,15 @@ tryReadTBQueueDefault (TBQueue rsize read _wsize write _size) = do
919919
return (Just x)
920920
[] -> do
921921
ys <- readTVar write
922-
case reverse ys of
922+
case ys of
923923
[] -> return Nothing
924+
_ -> do
925+
-- NB. lazy: we want the transaction to be
926+
-- short, otherwise it will conflict
927+
let ~(z,zs) = case reverse ys of
928+
z':zs' -> (z',zs')
929+
_ -> error "tryReadTBQueueDefault: impossible"
924930

925-
-- NB. lazy: we want the transaction to be
926-
-- short, otherwise it will conflict
927-
(z:zs) -> do
928931
writeTVar write []
929932
writeTVar read zs
930933
return (Just z)

io-sim/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Non-breaking changes
88

9+
* Removed a misleading internal comment.
10+
911
### 1.8.0.1
1012

1113
* Added support for `ghc-9.2`.

io-sim/src/Control/Monad/IOSim/STM.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ tryReadTBQueueDefault (TBQueue queue _size) = do
148148
case reverse ys of
149149
[] -> return Nothing
150150

151-
-- NB. lazy: we want the transaction to be
152-
-- short, otherwise it will conflict
153151
(z:zs) -> do
154152
writeTVar queue $! (zs, r', [], w)
155153
return (Just z)

0 commit comments

Comments
 (0)