From 895389181d1ff1f81e66e58572c181b0baec8b54 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 15 Feb 2023 05:03:50 +0000 Subject: [PATCH] Microptimize `Signal#getAndDiscreteUpdates` --- core/shared/src/main/scala/fs2/concurrent/Signal.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/shared/src/main/scala/fs2/concurrent/Signal.scala b/core/shared/src/main/scala/fs2/concurrent/Signal.scala index 62fbaca98c..c85940c2b4 100644 --- a/core/shared/src/main/scala/fs2/concurrent/Signal.scala +++ b/core/shared/src/main/scala/fs2/concurrent/Signal.scala @@ -287,9 +287,9 @@ object SignallingRef { def cleanup(id: Long): F[Unit] = state.update(s => s.copy(listeners = s.listeners - id)) - Resource.eval(state.get).map { s => + Resource.eval(state.get.map { s => (s.value, Stream.bracket(newId)(cleanup).flatMap(go(_, s.lastUpdate))) - } + }) } def set(a: A): F[Unit] = update(_ => a) @@ -565,14 +565,14 @@ object SignallingMapRef { } } - Resource.eval(state.get).map { state => + Resource.eval(state.get.map { state => ( state.keys.get(k).flatMap(_.value), Stream .bracket(newId)(cleanup) .flatMap(go(_, state.keys.get(k).fold(-1L)(_.lastUpdate))) ) - } + }) } def set(v: Option[V]): F[Unit] = update(_ => v)