Skip to content

Commit

Permalink
cleaned up some allocations and styling (#5855)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb authored Apr 20, 2022
1 parent 9194549 commit 8e7f021
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/core/Akka/Actor/ActorBase.Lifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using System;
using System.Linq;
using Akka.Util.Internal;

namespace Akka.Actor
{
public abstract partial class ActorBase
Expand Down Expand Up @@ -62,7 +64,7 @@ public virtual void AroundPostRestart(Exception cause, object message)
/// <param name="message">optionally the current message the actor processed when failing, if applicable.</param>
protected virtual void PreRestart(Exception reason, object message)
{
Context.GetChildren().ToList().ForEach(c =>
Context.GetChildren().ForEach(c =>
{
Context.Unwatch(c);
Context.Stop(c);
Expand Down
6 changes: 2 additions & 4 deletions src/core/Akka/Actor/Stash/IActorStash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public override bool CanBeAppliedTo(Type actorType)
/// <param name="context">TBD</param>
public override void AfterIncarnated(ActorBase actor, IActorContext context)
{
var stashed = actor as IActorStash;
if (stashed != null && stashed.Stash == null)
if (actor is IActorStash stashed && stashed.Stash == null)
{
stashed.Stash = context.CreateStash(actor.GetType());
}
Expand All @@ -62,8 +61,7 @@ public override void AfterIncarnated(ActorBase actor, IActorContext context)
/// <param name="context">TBD</param>
public override void BeforeIncarnated(ActorBase actor, IActorContext context)
{
var actorStash = actor as IActorStash;
if (actorStash != null)
if (actor is IActorStash actorStash)
{
actorStash.Stash.UnstashAll();
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka/Actor/Stash/Internal/AbstractStash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ public void Prepend(IEnumerable<Envelope> envelopes)
private void EnqueueFirst(Envelope msg)
{
Mailbox.EnqueueFirst(msg);
var terminatedMessage = msg.Message as Terminated;
if(terminatedMessage != null)
if(msg.Message is Terminated terminatedMessage)
{
_actorCell.TerminatedQueuedFor(terminatedMessage.ActorRef, Option<object>.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public bool TryDequeue(out Envelope envelope)
/// <inheritdoc cref="IMessageQueue"/>
public void CleanUp(IActorRef owner, IMessageQueue deadletters)
{
Envelope msg;
while (TryDequeue(out msg))
while (TryDequeue(out var msg))
{
deadletters.Enqueue(owner, msg);
}
Expand Down

0 comments on commit 8e7f021

Please sign in to comment.