Skip to content

Commit 731ec92

Browse files
authored
use Array.Empty (#6801)
1 parent 4e97b5a commit 731ec92

File tree

23 files changed

+38
-38
lines changed

23 files changed

+38
-38
lines changed

src/contrib/cluster/Akka.Cluster.Metrics.Tests/MetricSpec.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ public class NodeMetricSpec
7474
[Fact]
7575
public void NodeMetrics_Should_return_correct_result_for_2_same_nodes()
7676
{
77-
new NodeMetrics(_node1, 0, new NodeMetrics.Types.Metric[0])
78-
.SameAs(new NodeMetrics(_node1, 0, new NodeMetrics.Types.Metric[0]))
77+
new NodeMetrics(_node1, 0, Array.Empty<NodeMetrics.Types.Metric>())
78+
.SameAs(new NodeMetrics(_node1, 0, Array.Empty<NodeMetrics.Types.Metric>()))
7979
.Should().BeTrue();
8080
}
8181

8282
[Fact]
8383
public void NodeMetrics_Should_return_correct_result_for_2_not_same_nodes()
8484
{
85-
new NodeMetrics(_node1, 0, new NodeMetrics.Types.Metric[0])
86-
.SameAs(new NodeMetrics(_node2, 0, new NodeMetrics.Types.Metric[0]))
85+
new NodeMetrics(_node1, 0, Array.Empty<NodeMetrics.Types.Metric>())
86+
.SameAs(new NodeMetrics(_node2, 0, Array.Empty<NodeMetrics.Types.Metric>()))
8787
.Should().BeFalse();
8888
}
8989

src/contrib/cluster/Akka.Cluster.Metrics/Serialization/ClusterMetricsMessageSerializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public override byte[] ToBinary(object obj)
5454
case MetricsGossipEnvelope m: return Compress(MetricsGossipEnvelopeToProto(m)); // TODO: Add compression here
5555
case Metrics.AdaptiveLoadBalancingPool alb: return AdaptiveLoadBalancingPoolToBinary(alb);
5656
case Metrics.MixMetricsSelector mms: return MixMetricsSelectorToBinary(mms);
57-
case CpuMetricsSelector _: return new byte[0];
58-
case MemoryMetricsSelector _: return new byte[0];
57+
case CpuMetricsSelector _: return Array.Empty<byte>();
58+
case MemoryMetricsSelector _: return Array.Empty<byte>();
5959
default:
6060
throw new ArgumentException($"Can't serialize object of type ${obj.GetType().Name} in [${GetType().Name}]");
6161
}

src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionSerializerSetupSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void Setup_should_be_converted_to_settings_correctly()
6363
false,
6464
typeof(DummyTypesProvider),
6565
new Func<string, string>[] { s => $"{s}.." },
66-
new Surrogate[0],
66+
Array.Empty<Surrogate>(),
6767
true);
6868
var appliedSettings = setup.ApplySettings(settings);
6969

src/contrib/serializers/Akka.Serialization.Hyperion/HyperionSerializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public static HyperionSerializerSettings Create(Config config)
313313
/// <exception>Raised when `known-types-provider` type doesn't implement <see cref="IKnownTypesProvider"/> interface.</exception>
314314
[Obsolete]
315315
public HyperionSerializerSettings(bool preserveObjectReferences, bool versionTolerance, Type knownTypesProvider)
316-
: this(preserveObjectReferences, versionTolerance, knownTypesProvider, new List<Func<string, string>>(), new Surrogate[0], true, DisabledTypeFilter.Instance)
316+
: this(preserveObjectReferences, versionTolerance, knownTypesProvider, new List<Func<string, string>>(), Array.Empty<Surrogate>(), true, DisabledTypeFilter.Instance)
317317
{ }
318318

319319
/// <summary>
@@ -330,7 +330,7 @@ public HyperionSerializerSettings(
330330
bool versionTolerance,
331331
Type knownTypesProvider,
332332
IEnumerable<Func<string, string>> packageNameOverrides)
333-
: this(preserveObjectReferences, versionTolerance, knownTypesProvider, packageNameOverrides, new Surrogate[0], true, DisabledTypeFilter.Instance)
333+
: this(preserveObjectReferences, versionTolerance, knownTypesProvider, packageNameOverrides, Array.Empty<Surrogate>(), true, DisabledTypeFilter.Instance)
334334
{ }
335335

336336
/// <summary>

src/core/Akka.Cluster/SplitBrainResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public IEnumerable<Member> Apply(NetworkPartitionContext context)
139139

140140
if (remaining.Count < unreachable.Count) return context.Remaining;
141141
if (remaining.Count > unreachable.Count) return context.Unreachable;
142-
if (remaining.IsEmpty && unreachable.IsEmpty) return new Member[0];
142+
if (remaining.IsEmpty && unreachable.IsEmpty) return Array.Empty<Member>();
143143

144144
// if the parts are of equal size the part containing the node with the lowest address is kept.
145145
var oldest = remaining.Union(unreachable).First();

src/core/Akka.Persistence.Query/PersistenceQuery.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private IReadJournalProvider CreateType(Type pluginType, object[] parameters)
6262
if (ctor != null) return (IReadJournalProvider)ctor.Invoke(new[] { parameters[0] });
6363

6464
ctor = pluginType.GetConstructor(new Type[0]);
65-
if (ctor != null) return (IReadJournalProvider)ctor.Invoke(new object[0]);
65+
if (ctor != null) return (IReadJournalProvider)ctor.Invoke(Array.Empty<object>());
6666

6767
throw new ArgumentException($"Unable to create read journal plugin instance type {pluginType}!");
6868
}

src/core/Akka.Persistence.TCK/Serialization/SnapshotStoreSerializationSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public virtual void SnapshotStore_should_serialize_AtLeastOnceDeliverySnapshot_w
9595
{
9696
var probe = CreateTestProbe();
9797

98-
var unconfirmed = new UnconfirmedDelivery[0];
98+
var unconfirmed = Array.Empty<UnconfirmedDelivery>();
9999
var atLeastOnceDeliverySnapshot = new AtLeastOnceDeliverySnapshot(13, unconfirmed);
100100

101101
var metadata = new SnapshotMetadata(Pid, 2);

src/core/Akka.Remote.Tests/Serialization/MiscMessageSerializerSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void Serializer_must_reject_invalid_manifest()
376376
public void Serializer_must_reject_deserialization_with_invalid_manifest()
377377
{
378378
var serializer = new MiscMessageSerializer(Sys.AsInstanceOf<ExtendedActorSystem>());
379-
Action comparison = () => serializer.FromBinary(new byte[0], "INVALID");
379+
Action comparison = () => serializer.FromBinary(Array.Empty<byte>(), "INVALID");
380380
comparison.Should().Throw<SerializationException>();
381381
}
382382

src/core/Akka.Remote.Tests/TransientSerializationErrorSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public override byte[] ToBinary(object obj)
111111
case ToBinaryIllegal _:
112112
throw new ArgumentException();
113113
default:
114-
return new byte[0];
114+
return Array.Empty<byte>();
115115
}
116116
}
117117
}

src/core/Akka.Streams.Tests/Dsl/FlowIntersperseSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void A_Intersperse_must_surround_single_element_stream_with_start_and_end
107107
public void A_Intersperse_must_not_surround_empty_stream_with_null_start_and_stop()
108108
{
109109
var probe =
110-
Source.From(new int[0])
110+
Source.From(Array.Empty<int>())
111111
.Select(x => x.ToString())
112112
.Intersperse(",")
113113
.RunWith(this.SinkProbe<string>(), Materializer);

src/core/Akka.Streams.Tests/Dsl/FlowSelectManySpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public FlowSelectManySpec(ITestOutputHelper output) : base(output)
3535
public async Task SelectMany_should_map_and_concat()
3636
{
3737
var script = Script.Create(
38-
(new[] { 0 }, new int[0]),
38+
(new[] { 0 }, Array.Empty<int>()),
3939
(new[] { 1 }, new[] { 1 }),
4040
(new[] { 2 }, new[] { 2, 2 }),
4141
(new[] { 3 }, new[] { 3, 3, 3 }),

src/core/Akka.Streams.Tests/Dsl/FlowStatefulSelectManySpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void A_StatefulSelectMany_must_work_in_happy_case()
3737
{
3838
var phases = new[]
3939
{
40-
((ICollection<int>)new[] {2}, (ICollection<int>)new int[0]),
40+
((ICollection<int>)new[] {2}, (ICollection<int>)Array.Empty<int>()),
4141
((ICollection<int>)new[] {1}, (ICollection<int>)new[] {1, 1}),
4242
((ICollection<int>)new[] {3}, (ICollection<int>)new[] {3}),
4343
((ICollection<int>)new[] {6}, (ICollection<int>)new[] {6, 6, 6})

src/core/Akka.Streams.Tests/Dsl/RetrySpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void RetryConcat_should_concat_incremented_ints_and_modulo_3_incremented_
266266
{
267267
var s = (os + 1) % 3;
268268
if (os < 42) return new[] { (os + 1, os + 1), (s, s) };
269-
if (os == 42) return new (int, int)[0];
269+
if (os == 42) return Array.Empty<(int, int)>();
270270
return null;
271271
}))
272272
.ToMaterialized(this.SinkProbe<(Result<int>, int)>(), Keep.Both)

src/core/Akka.Streams.Tests/IO/InputStreamSinkSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ await this.AssertAllStagesStoppedAsync(() => {
191191

192192
Action(() => inputStream.Read(buf, -1, 2)).Should().Throw<ArgumentException>();
193193
Action(() => inputStream.Read(buf, 0, 5)).Should().Throw<ArgumentException>();
194-
Action(() => inputStream.Read(new byte[0], 0, 1)).Should().Throw<ArgumentException>();
194+
Action(() => inputStream.Read(Array.Empty<byte>(), 0, 1)).Should().Throw<ArgumentException>();
195195
Action(() => inputStream.Read(buf, 0, 0)).Should().Throw<ArgumentException>();
196196
return Task.CompletedTask;
197197
}, _materializer);

src/core/Akka.Streams.Tests/Implementation/Fusing/GraphInterpreterSpecKit.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public PortTestSetup(ActorSystem system, bool chasing = false) : base(system)
484484
var propagateStage = new EventPropagateStage();
485485

486486
var assembly = !chasing
487-
? new GraphAssembly(new IGraphStageWithMaterializedValue<Shape, object>[0], new Attributes[0],
487+
? new GraphAssembly(Array.Empty<IGraphStageWithMaterializedValue<Shape, object>>(), Array.Empty<Attributes>(),
488488
new Inlet[] {null}, new[] {-1}, new Outlet[] {null}, new[] {-1})
489489
: new GraphAssembly(new[] {propagateStage}, new[] {Attributes.None},
490490
new Inlet[] {propagateStage.In, null}, new[] {0, -1}, new Outlet[] {null, propagateStage.Out},

src/core/Akka.Streams.Tests/Implementation/Fusing/InterpreterSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void Interpreter_should_implement_chain_of_maps_correctly()
9696
[Fact]
9797
public void Interpreter_should_work_with_only_boundary_ops()
9898
{
99-
WithOneBoundedSetup(new IStage<int, int>[0],
99+
WithOneBoundedSetup(Array.Empty<IStage<int, int>>(),
100100
(lastEvents, upstream, downstream) =>
101101
{
102102
lastEvents().Should().BeEmpty();

src/core/Akka.Streams/Attributes.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public AfterDelay(TimeSpan delay, IStrategy strategy)
283283
/// <param name="attributes">TBD</param>
284284
public Attributes(params IAttribute[] attributes)
285285
{
286-
_attributes = attributes ?? new IAttribute[0];
286+
_attributes = attributes ?? Array.Empty<IAttribute>();
287287
}
288288

289289
/// <summary>

src/core/Akka.Tests/Actor/PropsSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Props_created_with_strategy_must_have_it_set()
6161
public void Props_created_with_null_type_must_throw()
6262
{
6363
Type missingType = null;
64-
object[] args = new object[0];
64+
object[] args = Array.Empty<object>();
6565
var argsEnumerable = Enumerable.Empty<object>();
6666
var defaultStrategy = SupervisorStrategy.DefaultStrategy;
6767
var defaultDeploy = Deploy.Local;

src/core/Akka.Tests/MatchHandler/CachedMatchCompilerTests.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class CachedMatchCompilerTests
2121
public void When_compiling_first_time_correct_calls_are_made_to_MatchExpressionBuilder_and_PartialActionBuilder()
2222
{
2323
//Arrange
24-
object[] argumentValues = new object[0];
24+
object[] argumentValues = Array.Empty<object>();
2525
Expression<Func<object, bool>> lambdaExpression = _ => true;
2626
var matchExpressionBuilder = new DummyMatchExpressionBuilder()
2727
{
@@ -60,12 +60,11 @@ public void When_compiling_first_time_correct_calls_are_made_to_MatchExpressionB
6060
public void When_compiling_second_time_with_same_signature_the_cached_version_should_be_used()
6161
{
6262
//Arrange
63-
object[] argumentValues = new object[0];
6463
Expression<Func<object, bool>> lambdaExpression = _ => true;
6564
var matchExpressionBuilder = new DummyMatchExpressionBuilder()
6665
{
67-
BuildLambdaExpressionResult = new MatchExpressionBuilderResult(lambdaExpression, argumentValues),
68-
CreateArgumentValuesArrayResult = argumentValues,
66+
BuildLambdaExpressionResult = new MatchExpressionBuilderResult(lambdaExpression, Array.Empty<object>()),
67+
CreateArgumentValuesArrayResult = Array.Empty<object>(),
6968
};
7069

7170
Func<object, bool> deleg = _ => true;
@@ -95,7 +94,7 @@ public void When_compiling_second_time_with_same_signature_the_cached_version_sh
9594
//Assert
9695

9796
AssertOneCall(to: matchExpressionBuilder.CreateArgumentValuesArrayCalls, withArgument: arguments, description: "CreateArgumentValuesArray");
98-
AssertOneCall(to: partialActionBuilder.BuildCalls, description: "Build", check: i => ReferenceEquals(i.CompiledDelegate, deleg) && ReferenceEquals(i.DelegateArguments, argumentValues));
97+
AssertOneCall(to: partialActionBuilder.BuildCalls, description: "Build", check: i => ReferenceEquals(i.CompiledDelegate, deleg) && ReferenceEquals(i.DelegateArguments, Array.Empty<object>()));
9998
Assert.Same(partialAction, resultPartialAction);
10099

101100
AssertNoCall(to: matchExpressionBuilder.BuildLambdaExpressionCalls, description: "BuildLambdaExpression");

src/core/Akka.Tests/MatchHandler/MatchBuilderSignatureTests.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// </copyright>
66
//-----------------------------------------------------------------------
77

8+
using System;
89
using Akka.Tools.MatchHandler;
910
using Xunit;
1011

@@ -16,7 +17,7 @@ public class MatchBuilderSignatureTests
1617
public void GetHashCode_should_return_same_value_for_empty_and_null_signatures()
1718
{
1819
var nullSignature = new MatchBuilderSignature(null);
19-
var emptySignature = new MatchBuilderSignature(new object[0]);
20+
var emptySignature = new MatchBuilderSignature(Array.Empty<object>());
2021

2122
Assert.Equal(nullSignature.GetHashCode(), emptySignature.GetHashCode());
2223
}
@@ -83,7 +84,7 @@ public void GetHashCode_should_be_different_when_same_elements_but_fewer()
8384
[Fact]
8485
public void Equals_with_null_should_be_false()
8586
{
86-
var signature = new MatchBuilderSignature(new object[0]);
87+
var signature = new MatchBuilderSignature(Array.Empty<object>());
8788
Assert.False(signature.Equals((object)null));
8889
Assert.False(signature.Equals(null));
8990
}
@@ -92,15 +93,15 @@ public void Equals_with_null_should_be_false()
9293
[Fact]
9394
public void Equals_with_same_should_be_true()
9495
{
95-
var signature = new MatchBuilderSignature(new object[0]);
96+
var signature = new MatchBuilderSignature(Array.Empty<object>());
9697
Assert.True(signature.Equals((object)signature));
9798
Assert.True(signature.Equals(signature));
9899
}
99100

100101
[Fact]
101102
public void Equals_with_different_type_should_be_false()
102103
{
103-
var signature = new MatchBuilderSignature(new object[0]);
104+
var signature = new MatchBuilderSignature(Array.Empty<object>());
104105
Assert.False(signature.Equals(new object()));
105106
}
106107

@@ -116,7 +117,7 @@ public void Equals_with_two_null_element_signatures_should_be_true()
116117
public void Equals_with_one_null_element_signature_and_one_empty_element_signature_should_be_true()
117118
{
118119
var signature1 = new MatchBuilderSignature(null);
119-
var signature2 = new MatchBuilderSignature(new object[0]);
120+
var signature2 = new MatchBuilderSignature(Array.Empty<object>());
120121
Assert.True(signature1.Equals(signature2));
121122
Assert.True(signature2.Equals(signature1));
122123
}

src/core/Akka.Tests/MatchHandler/PartialActionBuilderTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void Given_a_0_arguments_delegate_When_building_and_invoking_Then_the_sup
2222
object updatedValue = null;
2323
Func<object, bool> deleg = value => { updatedValue = value; return true; };
2424

25-
var partialAction = builder.Build<object>(new CompiledMatchHandlerWithArguments(deleg, new object[0]));
25+
var partialAction = builder.Build<object>(new CompiledMatchHandlerWithArguments(deleg, Array.Empty<object>()));
2626
partialAction("value");
2727
Assert.Same(updatedValue, "value");
2828
}

src/core/Akka/Routing/RouterConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public abstract class Group : RouterConfig, IEquatable<Group>
147147
protected Group(IEnumerable<string> paths, string routerDispatcher) : base(routerDispatcher)
148148
{
149149
// equivalent of turning the paths into an immutable sequence
150-
InternalPaths = paths?.ToArray() ?? new string[0];
150+
InternalPaths = paths?.ToArray() ?? Array.Empty<string>();
151151
}
152152

153153
/// <summary>

src/examples/Cluster/Roles/Samples.Cluster.Transformation/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ static void Main(string[] args)
2424
_clusterConfig = section.AkkaConfig;
2525
LaunchBackend(new []{ "2551" });
2626
LaunchBackend(new[] { "2552" });
27-
LaunchBackend(new string[0]);
28-
LaunchFrontend(new string[0]);
29-
LaunchFrontend(new string[0]);
27+
LaunchBackend(Array.Empty<string>());
28+
LaunchFrontend(Array.Empty<string>());
29+
LaunchFrontend(Array.Empty<string>());
3030
//starting 2 frontend nodes and 3 backend nodes
3131
Console.WriteLine("Press any key to exit.");
3232
Console.ReadLine();

0 commit comments

Comments
 (0)