mdedetrich commented on code in PR #983:
URL: https://github.com/apache/incubator-pekko/pull/983#discussion_r1460308242
##########
stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:
##########
@@ -259,10 +259,16 @@ 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)
+ //1. `applyOrElse` is faster than (`pf.isDefinedAt` and then
`pf.apply`)
+ //2. using reference comparing here instead of pattern matching can
generate less and quicker bytecode,
+ // eg: just a simple `IF_ACMPNE`, and you can find the same trick
in `CollectWhile` operator.
+ // If you interest, you can check the associated PR for this
change and the
+ // current implementation of
`scala.collection.IterableOnceOps.collectFirst`.
+ if (result.asInstanceOf[AnyRef] eq Collect.NotApplied) {
Review Comment:
For me its good, just need to wait for @pjfanning t ore-review this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]