Skip to content

Commit

Permalink
chore: Micro optimization for collect* operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed Jan 19, 2024
1 parent 7b2a3d8 commit a6243fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ private[pekko] final class CollectWhile[In, Out](pf: PartialFunction[In, Out]) e

override final def onPush(): Unit =
try {
pf.applyOrElse(grab(in), NotApplied) match {
case NotApplied => completeStage()
case result: Out @unchecked => push(out, result)
case _ => throw new RuntimeException() // won't happen, compiler exhaustiveness check pleaser
val result = pf.applyOrElse(grab(in), NotApplied)
if (result.asInstanceOf[AnyRef] eq NotApplied) {
completeStage()
} else {
push(out, result)
}
} catch {
case NonFatal(ex) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ private[stream] object Collect {

override def onPush(): Unit =
try {
pf.applyOrElse(grab(in), NotApplied) match {
case NotApplied => pull(in)
case result: Out @unchecked => push(out, result)
case _ => throw new RuntimeException() // won't happen, compiler exhaustiveness check pleaser
val result = pf.applyOrElse(grab(in), NotApplied)
if (result.asInstanceOf[AnyRef] eq Collect.NotApplied) {
pull(in)
} else {
push(out, result)
}
} catch {
case NonFatal(ex) =>
Expand Down

0 comments on commit a6243fc

Please sign in to comment.