Skip to content

Commit 9c65fcd

Browse files
committed
simulation: some strictness in ModelTCP
1 parent 6185119 commit 9c65fcd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

simulation/src/ModelTCP.hs

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module ModelTCP (
2525

2626
import Control.Exception (assert)
2727
import Data.Aeson
28-
import Data.Foldable as Foldable (Foldable (sum))
28+
import Data.Foldable as Foldable (Foldable (sum, toList))
2929
import Data.List.NonEmpty (NonEmpty ((:|)))
3030
import qualified Data.List.NonEmpty as NE
3131
import Data.PQueue.Prio.Min (MinPQueue)
@@ -181,9 +181,10 @@ forecastTcpMsgSend
181181
tcpstate0
182182
now0
183183
msgsize0 =
184-
let (forecasts, tcpstate) = trySend [] tcpstate0 now0 msgsize0
185-
overallforecast = sconcat forecasts
186-
in (overallforecast, mergeAdjacentForecasts forecasts, tcpstate)
184+
let (forecasts, !tcpstate) = trySend [] tcpstate0 now0 msgsize0
185+
!mergedForecasts = mergeAdjacentForecasts forecasts
186+
!overallforecast = sconcat mergedForecasts
187+
in (overallforecast, toList mergedForecasts, tcpstate)
187188
where
188189
trySend ::
189190
[TcpMsgForecast] ->
@@ -340,9 +341,11 @@ forecastTcpMsgSend
340341

341342
-- | To make the result easier to interpret, merge together any fragments
342343
-- that are in fact contiguous.
343-
mergeAdjacentForecasts :: NonEmpty TcpMsgForecast -> [TcpMsgForecast]
344+
mergeAdjacentForecasts :: NonEmpty TcpMsgForecast -> NonEmpty TcpMsgForecast
344345
mergeAdjacentForecasts (forecast0 :| forecasts0) =
345-
go forecast0 forecasts0
346+
case go forecast0 forecasts0 of
347+
[] -> error "internal: merged into empty"
348+
(x : xs) -> x :| xs
346349
where
347350
go forecast (forecast' : forecasts)
348351
| msgSendTrailingEdge forecast == msgSendLeadingEdge forecast' =

0 commit comments

Comments
 (0)