Skip to content

Commit

Permalink
use target typed new when type is obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jun 16, 2023
1 parent 6d433e0 commit 44a1748
Show file tree
Hide file tree
Showing 557 changed files with 1,569 additions and 1,634 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ActorMessagingMemoryPressureBenchmark
public sealed class StopActor
{
private StopActor(){}
public static readonly StopActor Instance = new StopActor();
public static readonly StopActor Instance = new();
}

public sealed class MyActor : ReceiveActor
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Benchmarks/Actor/ActorPathBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ActorPathBenchmarks
private ActorPath x;
private ActorPath y;
private ActorPath _childPath;
private Address _sysAdr = new Address("akka.tcp", "system", "127.0.0.1", 1337);
private Address _otherAdr = new Address("akka.tcp", "system", "127.0.0.1", 1338);
private Address _sysAdr = new("akka.tcp", "system", "127.0.0.1", 1337);
private Address _otherAdr = new("akka.tcp", "system", "127.0.0.1", 1338);

private string _actorPathStr;

Expand Down
10 changes: 5 additions & 5 deletions src/benchmark/Akka.Benchmarks/Actor/GetChildBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ protected override void OnReceive(object message)
private ActorSystem _system;
private IActorRef _parentActor;

private ActorWithChild.Get _getMessage = new ActorWithChild.Get("food");
private ActorWithChild.Create _createMessage = new ActorWithChild.Create("food");
private ActorWithChild.Get _getMessage = new("food");
private ActorWithChild.Create _createMessage = new("food");

private IActorContext _cell;
private RepointableActorRef _repointableActorRef;
private LocalActorRef _localActorRef;
private VirtualPathContainer _virtualPathContainer;

private List<string> _rpChildQueryPath = new List<string>() { "food", "ood", "od" };
private List<string> _lclChildQueryPath = new List<string>() { "ood", "od", "d" };
private List<string> _virtualPathContainerQueryPath = new List<string>() { "foo" };
private List<string> _rpChildQueryPath = new() { "food", "ood", "od" };
private List<string> _lclChildQueryPath = new() { "ood", "od", "d" };
private List<string> _virtualPathContainerQueryPath = new() { "foo" };

[GlobalSetup]
public async Task Setup()
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task Actor_ping_pong_single_pair_in_memory()

sealed class StartTest
{
public static readonly StartTest Instance = new StartTest();
public static readonly StartTest Instance = new();
private StartTest() { }
}

Expand All @@ -65,7 +65,7 @@ public Signal(int remaining)

sealed class TestDone
{
public static readonly TestDone Instance = new TestDone();
public static readonly TestDone Instance = new();
private TestDone() { }
}

Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public StartTest(int actorCount) {

sealed class ChildReady
{
public static readonly ChildReady Instance = new ChildReady();
public static readonly ChildReady Instance = new();
private ChildReady() { }
}

sealed class TestDone
{
public static readonly TestDone Instance = new TestDone();
public static readonly TestDone Instance = new();
private TestDone() { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class ReachabilityBenchmarks
[Params(100)]
public int Iterations;

public Address Address = new Address("akka", "sys", "a", 2552);
public Address Node = new Address("akka", "sys", "a", 2552);
public Address Address = new("akka", "sys", "a", 2552);
public Address Node = new("akka", "sys", "a", 2552);

private Reachability CreateReachabilityOfSize(Reachability baseReachability, int size)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public EchoConnection(IActorRef connection)

private class ClientCoordinator : ReceiveActor
{
private readonly HashSet<IActorRef> _waitingChildren = new HashSet<IActorRef>();
private readonly HashSet<IActorRef> _waitingChildren = new();
private IActorRef _requester;

public ClientCoordinator(string host, int port, int clientsCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class AkkaPduCodecBenchmark
/// </summary>
private readonly object _message = "foobar";

private readonly Ack _lastAck = new Ack(-1);
private readonly Ack _lastAck = new(-1);

private ByteString _fullDecode;
private ByteString _pduDecoded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Akka.Cluster.Benchmarks.Persistence
[Config(typeof(MicroBenchmarkConfig))]
public class JournalWriteBenchmarks
{
private static readonly Store Message = new Store(1);
private static readonly Store Message = new(1);

[Params(1, 10, 100)] public int PersistentActors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ namespace Akka.Cluster.Benchmarks.Persistence
{
public sealed class Init
{
public static readonly Init Instance = new Init();
public static readonly Init Instance = new();
private Init() { }
}

public sealed class Finish
{
public static readonly Finish Instance = new Finish();
public static readonly Finish Instance = new();
private Finish() { }
}

public sealed class Done
{
public static readonly Done Instance = new Done();
public static readonly Done Instance = new();
private Done() { }
}

Expand All @@ -45,7 +45,7 @@ public Finished(long state)

public sealed class RecoveryFinished
{
public static readonly RecoveryFinished Instance = new RecoveryFinished();
public static readonly RecoveryFinished Instance = new();

private RecoveryFinished() { }
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public Stored(int value)
/// </summary>
public sealed class IsFinished
{
public static readonly IsFinished Instance = new IsFinished();
public static readonly IsFinished Instance = new();
private IsFinished(){}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ protected override bool ReceiveCommand(object message){


public static class PersistenceInfrastructure{
public static readonly AtomicCounter DbCounter = new AtomicCounter(0);
public static readonly AtomicCounter DbCounter = new(0);

public static Config GenerateJournalConfig(){
var config = ConfigurationFactory.ParseString(@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Akka.Cluster.Benchmarks.Sharding
[Config(typeof(MicroBenchmarkConfig))]
public class HashCodeMessageExtractorBenchmarks
{
private ShardingEnvelope _m1 = new ShardingEnvelope("foo", 1);
private ShardedMessage _m2 = new ShardedMessage("foo", 1);
private ShardingEnvelope _m1 = new("foo", 1);
private ShardedMessage _m2 = new("foo", 1);
private IMessageExtractor _extractor = new ShardMessageExtractor();

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class ShardedEntityActor : ReceiveActor
{
public sealed class Resolve
{
public static readonly Resolve Instance = new Resolve();
public static readonly Resolve Instance = new();
private Resolve(){}
}

Expand Down Expand Up @@ -211,7 +211,7 @@ public override string EntityId(object message)

public static class ShardingHelper
{
public static AtomicCounter DbId = new AtomicCounter(0);
public static AtomicCounter DbId = new(0);

internal static string BoolToToggle(bool val)
{
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Cluster.Cpu.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static class Program

private const int DefaultWarmUpRepeat = 5;

private static readonly List<CpuUsage> Usages = new List<CpuUsage>();
private static readonly List<Process> Processes = new List<Process>();
private static readonly List<CpuUsage> Usages = new();
private static readonly List<Process> Processes = new();

public static async Task<int> Main(string[] args)
{
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/RemotePingPong/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private class AllStartedActor : UntypedActor
{
public class AllStarted { }

private readonly HashSet<IActorRef> _actors = new HashSet<IActorRef>();
private readonly HashSet<IActorRef> _actors = new();
private int _correlationId = 0;

protected override void OnReceive(object message)
Expand Down
5 changes: 2 additions & 3 deletions src/benchmark/SerializationBenchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public JsonSerializerTests()
_poolSer =
_sys_pool.Serialization.FindSerializerForType(typeof(object));
}
private static TestSer testObj = new TestSer()
private static TestSer testObj = new()
{
Id = 124,
someStr =
Expand Down Expand Up @@ -123,8 +123,7 @@ public SerializationTests()
_ser = _sys.Serialization.FindSerializerForType(typeof(MyType));
}

public static MyType payload =>
new MyType() { SomeInt = 1, SomeStr = "lol" };
public static MyType payload => new() { SomeInt = 1, SomeStr = "lol" };
[Benchmark]
public void Serialization_WithTransport_NoState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AdaptiveLoadBalancingRouterConfig : MultiNodeConfig
public sealed class AllocateMemory
{
private AllocateMemory() { }
public static readonly AllocateMemory Instance = new AllocateMemory();
public static readonly AllocateMemory Instance = new();
}

[Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ClusterMetricsCollector : ActorBase
sealed class MetricsTick
{
private MetricsTick() { }
public static readonly MetricsTick Instance = new MetricsTick();
public static readonly MetricsTick Instance = new();
}

/// <summary>
Expand All @@ -48,7 +48,7 @@ private MetricsTick() { }
sealed class GossipTick
{
private GossipTick() { }
public static readonly GossipTick Instance = new GossipTick();
public static readonly GossipTick Instance = new();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private CollectionStartMessage(){ }
/// <summary>
/// Singleton instance for
/// </summary>
public static readonly CollectionStartMessage Instance = new CollectionStartMessage();
public static readonly CollectionStartMessage Instance = new();
}

/// <summary>
Expand All @@ -107,7 +107,7 @@ private CollectionStopMessage(){ }
/// <summary>
/// Singleton instance for
/// </summary>
public static readonly CollectionStopMessage Instance = new CollectionStopMessage();
public static readonly CollectionStopMessage Instance = new();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Akka.Cluster.Metrics
/// </summary>
internal static class DateTimeExtensions
{
private static readonly DateTime UnixOffset = new DateTime(1970, 1, 1);
private static readonly DateTime UnixOffset = new(1970, 1, 1);

/// <summary>
/// Converts given date and time to UNIX Timestamp - number of milliseconds elapsed since 1 Jan 1970
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public class MemoryMetricsSelector : CapacityMetricsSelector
/// <summary>
/// Singleton instance
/// </summary>
public static readonly MemoryMetricsSelector Instance = new MemoryMetricsSelector();
public static readonly MemoryMetricsSelector Instance = new();

/// <inheritdoc />
public override IImmutableDictionary<Actor.Address, double> Capacity(IImmutableSet<NodeMetrics> nodeMetrics)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public class CpuMetricsSelector : CapacityMetricsSelector
/// <summary>
/// Singleton instance
/// </summary>
public static readonly CpuMetricsSelector Instance = new CpuMetricsSelector();
public static readonly CpuMetricsSelector Instance = new();

public CpuMetricsSelector()
{
Expand Down Expand Up @@ -198,7 +198,7 @@ public MixMetricsSelector(ImmutableArray<CapacityMetricsSelector> selectors) : b
/// Singleton instance of the default MixMetricsSelector, which uses <see cref="MemoryMetricsSelector"/> and
/// <see cref="CpuMetricsSelector"/>
/// </summary>
public static readonly MixMetricsSelector Instance = new MixMetricsSelector(
public static readonly MixMetricsSelector Instance = new(
ImmutableArray.Create<CapacityMetricsSelector>(
MemoryMetricsSelector.Instance,
CpuMetricsSelector.Instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class MetricsGossip
/// <summary>
/// Empty metrics gossip
/// </summary>
public static readonly MetricsGossip Empty = new MetricsGossip(ImmutableHashSet<NodeMetrics>.Empty);
public static readonly MetricsGossip Empty = new(ImmutableHashSet<NodeMetrics>.Empty);

public MetricsGossip(IImmutableSet<NodeMetrics> nodes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public abstract class AsyncWriteProxyEx : AsyncWriteJournal, IWithUnboundedStash
{
private class InitTimeout
{
public static readonly InitTimeout Instance = new InitTimeout();
public static readonly InitTimeout Instance = new();
private InitTimeout() { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override bool Receive(object message)

internal class GetLocations
{
public static readonly GetLocations Instance = new GetLocations();
public static readonly GetLocations Instance = new();

private GetLocations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override bool Receive(object message)

internal class GetLocations
{
public static readonly GetLocations Instance = new GetLocations();
public static readonly GetLocations Instance = new();

private GetLocations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public abstract class ClusterShardingCustomShardAllocationSpec : MultiNodeCluste

internal class AllocateReq
{
public static readonly AllocateReq Instance = new AllocateReq();
public static readonly AllocateReq Instance = new();

private AllocateReq()
{
Expand All @@ -89,7 +89,7 @@ public UseRegion(IActorRef region)

internal class UseRegionAck
{
public static readonly UseRegionAck Instance = new UseRegionAck();
public static readonly UseRegionAck Instance = new();

private UseRegionAck()
{
Expand All @@ -98,7 +98,7 @@ private UseRegionAck()

internal class RebalanceReq
{
public static readonly RebalanceReq Instance = new RebalanceReq();
public static readonly RebalanceReq Instance = new();

private RebalanceReq()
{
Expand All @@ -117,7 +117,7 @@ public RebalanceShards(IImmutableSet<string> shards)

internal class RebalanceShardsAck
{
public static readonly RebalanceShardsAck Instance = new RebalanceShardsAck();
public static readonly RebalanceShardsAck Instance = new();

private RebalanceShardsAck()
{
Expand Down
Loading

0 comments on commit 44a1748

Please sign in to comment.