Eliminate the allocation on each aroundRecieve #20748
This commit is contained in:
parent
088aeb7c96
commit
213fa616a8
1 changed files with 16 additions and 1 deletions
|
|
@ -364,6 +364,16 @@ object Actor {
|
|||
* that will be translated to the receiving system's deadLetters.
|
||||
*/
|
||||
final val noSender: ActorRef = null
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
private final val NotHandled = new Object
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
private final val notHandledFun = (_: Any) ⇒ NotHandled
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -481,7 +491,12 @@ trait Actor {
|
|||
* @param receive current behavior.
|
||||
* @param msg current message.
|
||||
*/
|
||||
protected[akka] def aroundReceive(receive: Actor.Receive, msg: Any): Unit = receive.applyOrElse(msg, unhandled)
|
||||
protected[akka] def aroundReceive(receive: Actor.Receive, msg: Any): Unit = {
|
||||
// optimization: avoid allocation of lambda
|
||||
if (receive.applyOrElse(msg, Actor.notHandledFun).asInstanceOf[AnyRef] eq Actor.NotHandled) {
|
||||
unhandled(msg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be overridden to intercept calls to `preStart`. Calls `preStart` by default.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue