act Avoid deadletter access if not needed (#26422)

This commit is contained in:
Johannes Rudolph 2019-03-05 14:09:38 +01:00 committed by GitHub
parent 27957649e8
commit 971bd5159e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -290,7 +290,10 @@ private[akka] abstract class Mailbox(val messageQueue: MessageQueue)
* if we closed the mailbox, we must dump the remaining system messages * if we closed the mailbox, we must dump the remaining system messages
* to deadLetters (this is essential for DeathWatch) * to deadLetters (this is essential for DeathWatch)
*/ */
val dlm = actor.dispatcher.mailboxes.deadLetterMailbox val dlm: Mailbox =
// MICRO-OPT: `actor` is volatile, so the access is slow enough to avoid if not needed
if (messageList.nonEmpty) actor.dispatcher.mailboxes.deadLetterMailbox
else null
while (messageList.nonEmpty) { while (messageList.nonEmpty) {
val msg = messageList.head val msg = messageList.head
messageList = messageList.tail messageList = messageList.tail