Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Array.Empty<T>() to efficiently create empty arrays #570

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FluentNHibernate.MappingModel;
Expand Down Expand Up @@ -283,7 +283,7 @@ protected static CollectionMapping collection<T>(Expression<Func<T, object>> exp
protected static void Visit(params CollectionMapping[] mappings)
{
mappings.Each(visitor.Visit);
visitor.Visit(new HibernateMapping[0]); // simulate end of visit
visitor.Visit(Array.Empty<HibernateMapping>()); // simulate end of visit
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using FakeItEasy;
using FluentNHibernate.Diagnostics;
using FluentNHibernate.Testing.Utils;
Expand All @@ -22,7 +22,7 @@ public void should_publish_results_to_all_listeners()
{
var firstListener = A.Fake<IDiagnosticListener>();
var secondListener = A.Fake<IDiagnosticListener>();
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());

dispatcher.RegisterListener(firstListener);
dispatcher.RegisterListener(secondListener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using FakeItEasy;
using FluentNHibernate.Diagnostics;
using FluentNHibernate.Testing.Utils;
Expand All @@ -12,7 +12,7 @@ public class StringLambdaOutputListenerTests
[Test]
public void should_format_results()
{
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());
var formatter = A.Fake<IDiagnosticResultsFormatter>();
var listener = new StringLambdaOutputListener(x => { });
listener.SetFormatter(formatter);
Expand All @@ -24,7 +24,7 @@ public void should_format_results()
[Test]
public void should_raise_formatted_results()
{
var results = new DiagnosticResults(new ScannedSource[0], new Type[0], new Type[0], new SkippedAutomappingType[0], new Type[0], new AutomappingType[0]);
var results = new DiagnosticResults(Array.Empty<ScannedSource>(), Array.Empty<Type>(), Array.Empty<Type>(), Array.Empty<SkippedAutomappingType>(), Array.Empty<Type>(), Array.Empty<AutomappingType>());
var output = "formatted output";
var receivedOutput = "";
var formatter = A.Fake<IDiagnosticResultsFormatter>();
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate.Testing/EmptySource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using FluentNHibernate.Diagnostics;

Expand All @@ -8,7 +8,7 @@ internal class EmptySource : ITypeSource
{
public IEnumerable<Type> GetTypes()
{
return new Type[0];
return Array.Empty<Type>();
}

public void LogSource(IDiagnosticLogger logger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FakeItEasy;
using System;
using FakeItEasy;
using FluentNHibernate.Mapping.Providers;
using FluentNHibernate.MappingModel;
using FluentNHibernate.MappingModel.ClassBased;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class when_the_component_reference_resolution_visitor_processes_a_compone
{
public override void establish_context()
{
visitor = new ComponentReferenceResolutionVisitor(new[] { new ComponentMapComponentReferenceResolver() }, new IExternalComponentMappingProvider[0]);
visitor = new ComponentReferenceResolutionVisitor(new[] { new ComponentMapComponentReferenceResolver() }, Array.Empty<IExternalComponentMappingProvider>());
memberProperty = new DummyPropertyInfo("Component", typeof(ComponentTarget)).ToMember();
}

Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Automapping/AutoMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ IPropertyIgnorer IPropertyIgnorer.IgnoreProperty(string name)

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/FluentNHibernate/DummyMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override Type ReturnType

public override object[] GetCustomAttributes(bool inherit)
{
return new object[0];
return Array.Empty<object>();
}

public override bool IsDefined(Type attributeType, bool inherit)
Expand All @@ -32,7 +32,7 @@ public override bool IsDefined(Type attributeType, bool inherit)

public override ParameterInfo[] GetParameters()
{
return new ParameterInfo[0];
return Array.Empty<ParameterInfo>();
}

public override MethodImplAttributes GetMethodImplementationFlags()
Expand Down Expand Up @@ -82,7 +82,7 @@ public override MethodAttributes Attributes

public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
return new object[0];
return Array.Empty<object>();
}
}
}
10 changes: 5 additions & 5 deletions src/FluentNHibernate/DummyPropertyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Reflection;

Expand Down Expand Up @@ -31,7 +31,7 @@ public override int MetadataToken

public override object[] GetCustomAttributes(bool inherit)
{
return new object[0];
return Array.Empty<object>();
}

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

public override MethodInfo[] GetAccessors(bool nonPublic)
{
return new MethodInfo[0];
return Array.Empty<MethodInfo>();
}

public override MethodInfo GetGetMethod(bool nonPublic)
Expand All @@ -64,7 +64,7 @@ public override MethodInfo GetSetMethod(bool nonPublic)

public override ParameterInfo[] GetIndexParameters()
{
return new ParameterInfo[0];
return Array.Empty<ParameterInfo>();
}

public override string Name
Expand Down Expand Up @@ -104,7 +104,7 @@ public override bool CanWrite

public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
return new object[0];
return Array.Empty<object>();
}
}
}
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Mapping/ClassMap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
Expand Down Expand Up @@ -724,7 +724,7 @@ string GetDefaultTableName()

IEnumerable<Member> IMappingProvider.GetIgnoredProperties()
{
return new Member[0];
return Array.Empty<Member>();
}
}
}
2 changes: 1 addition & 1 deletion src/FluentNHibernate/MappingModel/TypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public bool IsNullable
public Type[] GetGenericArguments()
{
if (innerType == null)
return new Type[0];
return Array.Empty<Type>();

return innerType.GetGenericArguments();
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/PersistenceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public HibernateMapping GetHibernateMapping()

public IEnumerable<Member> GetIgnoredProperties()
{
return new Member[0];
return Array.Empty<Member>();
}
}
}
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Visitors/SeparateSubclassVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private IEnumerable<IIndeterminateSubclassMappingProvider> FindClosestSubclasses
var subclasses = SortByDistanceFrom(type, subclassProviders.Except(extendsSubclasses));

if (subclasses.Keys.Count == 0 && !extendsSubclasses.Any())
return new IIndeterminateSubclassMappingProvider[0];
return Array.Empty<IIndeterminateSubclassMappingProvider>();
if (subclasses.Keys.Count == 0)
return extendsSubclasses;

Expand Down