Skip to content

Commit 9b59d36

Browse files
Use Array.Empty<T>() to efficiently create empty arrays (#570)
+semver:patch
1 parent 850b5f3 commit 9b59d36

File tree

12 files changed

+26
-25
lines changed

12 files changed

+26
-25
lines changed

src/FluentNHibernate.Specs/Visitors/BiDirectionalManyToManyPairingVisitorSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq.Expressions;
44
using FluentNHibernate.MappingModel;
@@ -283,7 +283,7 @@ protected static CollectionMapping collection<T>(Expression<Func<T, object>> exp
283283
protected static void Visit(params CollectionMapping[] mappings)
284284
{
285285
mappings.Each(visitor.Visit);
286-
visitor.Visit(new HibernateMapping[0]); // simulate end of visit
286+
visitor.Visit(Array.Empty<HibernateMapping>()); // simulate end of visit
287287
}
288288
}
289289

src/FluentNHibernate.Testing/Diagnostics/DiagnosticMessageDespatcherTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using FakeItEasy;
33
using FluentNHibernate.Diagnostics;
44
using FluentNHibernate.Testing.Utils;
@@ -22,7 +22,7 @@ public void should_publish_results_to_all_listeners()
2222
{
2323
var firstListener = A.Fake<IDiagnosticListener>();
2424
var secondListener = A.Fake<IDiagnosticListener>();
25-
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
25+
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());
2626

2727
dispatcher.RegisterListener(firstListener);
2828
dispatcher.RegisterListener(secondListener);

src/FluentNHibernate.Testing/Diagnostics/StringLambdaOutputListenerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using FakeItEasy;
33
using FluentNHibernate.Diagnostics;
44
using FluentNHibernate.Testing.Utils;
@@ -12,7 +12,7 @@ public class StringLambdaOutputListenerTests
1212
[Test]
1313
public void should_format_results()
1414
{
15-
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
15+
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());
1616
var formatter = A.Fake<IDiagnosticResultsFormatter>();
1717
var listener = new StringLambdaOutputListener(x => { });
1818
listener.SetFormatter(formatter);
@@ -24,7 +24,7 @@ public void should_format_results()
2424
[Test]
2525
public void should_raise_formatted_results()
2626
{
27-
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
27+
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());
2828
var output = "formatted output";
2929
var receivedOutput = "";
3030
var formatter = A.Fake<IDiagnosticResultsFormatter>();

src/FluentNHibernate.Testing/EmptySource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using FluentNHibernate.Diagnostics;
44

@@ -8,7 +8,7 @@ internal class EmptySource : ITypeSource
88
{
99
public IEnumerable<Type> GetTypes()
1010
{
11-
return new Type[0];
11+
return Array.Empty<Type>();
1212
}
1313

1414
public void LogSource(IDiagnosticLogger logger)

src/FluentNHibernate.Testing/Visitors/ComponentReferenceResolutionVisitorSpecs.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FakeItEasy;
1+
using System;
2+
using FakeItEasy;
23
using FluentNHibernate.Mapping.Providers;
34
using FluentNHibernate.MappingModel;
45
using FluentNHibernate.MappingModel.ClassBased;
@@ -44,7 +45,7 @@ public class when_the_component_reference_resolution_visitor_processes_a_compone
4445
{
4546
public override void establish_context()
4647
{
47-
visitor = new ComponentReferenceResolutionVisitor(new[] { new ComponentMapComponentReferenceResolver() }, new IExternalComponentMappingProvider[0]);
48+
visitor = new ComponentReferenceResolutionVisitor(new[] { new ComponentMapComponentReferenceResolver() }, Array.Empty<IExternalComponentMappingProvider>());
4849
memberProperty = new DummyPropertyInfo("Component", typeof(ComponentTarget)).ToMember();
4950
}
5051

src/FluentNHibernate/Automapping/AutoMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ IPropertyIgnorer IPropertyIgnorer.IgnoreProperty(string name)
111111

112112
IPropertyIgnorer IPropertyIgnorer.IgnoreProperties(string first, params string[] others)
113113
{
114-
var options = (others ?? new string[0]).Concat(new[] { first }).ToArray();
114+
var options = (others ?? Array.Empty<string>()).Concat(new[] { first }).ToArray();
115115

116116
((IPropertyIgnorer)this).IgnoreProperties(x => x.Name.In(options));
117117

src/FluentNHibernate/DummyMethodInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override Type ReturnType
2222

2323
public override object[] GetCustomAttributes(bool inherit)
2424
{
25-
return new object[0];
25+
return Array.Empty<object>();
2626
}
2727

2828
public override bool IsDefined(Type attributeType, bool inherit)
@@ -32,7 +32,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
3232

3333
public override ParameterInfo[] GetParameters()
3434
{
35-
return new ParameterInfo[0];
35+
return Array.Empty<ParameterInfo>();
3636
}
3737

3838
public override MethodImplAttributes GetMethodImplementationFlags()
@@ -82,7 +82,7 @@ public override MethodAttributes Attributes
8282

8383
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
8484
{
85-
return new object[0];
85+
return Array.Empty<object>();
8686
}
8787
}
8888
}

src/FluentNHibernate/DummyPropertyInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Globalization;
33
using System.Reflection;
44

@@ -31,7 +31,7 @@ public override int MetadataToken
3131

3232
public override object[] GetCustomAttributes(bool inherit)
3333
{
34-
return new object[0];
34+
return Array.Empty<object>();
3535
}
3636

3737
public override bool IsDefined(Type attributeType, bool inherit)
@@ -49,7 +49,7 @@ public override void SetValue(object obj, object value, BindingFlags invokeAttr,
4949

5050
public override MethodInfo[] GetAccessors(bool nonPublic)
5151
{
52-
return new MethodInfo[0];
52+
return Array.Empty<MethodInfo>();
5353
}
5454

5555
public override MethodInfo GetGetMethod(bool nonPublic)
@@ -64,7 +64,7 @@ public override MethodInfo GetSetMethod(bool nonPublic)
6464

6565
public override ParameterInfo[] GetIndexParameters()
6666
{
67-
return new ParameterInfo[0];
67+
return Array.Empty<ParameterInfo>();
6868
}
6969

7070
public override string Name
@@ -104,7 +104,7 @@ public override bool CanWrite
104104

105105
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
106106
{
107-
return new object[0];
107+
return Array.Empty<object>();
108108
}
109109
}
110110
}

src/FluentNHibernate/Mapping/ClassMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq.Expressions;
@@ -724,7 +724,7 @@ string GetDefaultTableName()
724724

725725
IEnumerable<Member> IMappingProvider.GetIgnoredProperties()
726726
{
727-
return new Member[0];
727+
return Array.Empty<Member>();
728728
}
729729
}
730730
}

src/FluentNHibernate/MappingModel/TypeReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public bool IsNullable
9999
public Type[] GetGenericArguments()
100100
{
101101
if (innerType == null)
102-
return new Type[0];
102+
return Array.Empty<Type>();
103103

104104
return innerType.GetGenericArguments();
105105
}

0 commit comments

Comments
 (0)