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

Optimize empty arrays usages #1490

Merged
merged 2 commits into from
Dec 16, 2017
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
1 change: 1 addition & 0 deletions src/NHibernate.DomainModel/Async/CustomPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using NHibernate.Tuple.Entity;
using NHibernate.Type;
using NHibernate.Util;
using Array = System.Array;

namespace NHibernate.DomainModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.DomainModel/Baz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public void SetDefaults()
StringArray = StringSet.ToArray();
StringList = new List<string>(StringArray);
IntArray = new int[] {1, 3, 3, 7};
FooArray = new Foo[0];
FooArray = Array.Empty<Foo>();

Customs = new List<string[]>();
Customs.Add(new String[] {"foo", "bar"});
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate.DomainModel/CustomPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using NHibernate.Tuple.Entity;
using NHibernate.Type;
using NHibernate.Util;
using Array = System.Array;

namespace NHibernate.DomainModel
{
Expand Down Expand Up @@ -130,12 +131,12 @@ public bool[] PropertyInsertability

public ValueInclusion[] PropertyInsertGenerationInclusions
{
get { return new ValueInclusion[0]; }
get { return Array.Empty<ValueInclusion>(); }
}

public ValueInclusion[] PropertyUpdateGenerationInclusions
{
get { return new ValueInclusion[0]; }
get { return Array.Empty<ValueInclusion>(); }
}

public bool[] PropertyCheckability
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/Component/Basic/ComponentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override string MappingsAssembly

protected override System.Collections.IList Mappings
{
get { return new string[] { }; }
get { return Array.Empty<string>(); }
}

protected override void Configure(Configuration configuration)
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/DialectTest/DialectFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task CurrentTimestampSelectionAsync()

using (var connection = await (sessions.ConnectionProvider.GetConnectionAsync(CancellationToken.None)))
{
var statement = driver.GenerateCommand(CommandType.Text, new SqlString(dialect.CurrentTimestampSelectString), new SqlType[0]);
var statement = driver.GenerateCommand(CommandType.Text, new SqlString(dialect.CurrentTimestampSelectString), Array.Empty<SqlType>());
statement.Connection = connection;
using (var reader = await (statement.ExecuteReaderAsync()))
{
Expand Down
11 changes: 6 additions & 5 deletions src/NHibernate.Test/Async/Events/PostEvents/PostUpdateFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//------------------------------------------------------------------------------


using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Event;
Expand Down Expand Up @@ -56,7 +57,7 @@ public async Task ImplicitFlushAsync()
}

await (DbCleanupAsync());
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[0];
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = Array.Empty<IPostUpdateEventListener>();
}

[Test]
Expand Down Expand Up @@ -85,7 +86,7 @@ public async Task ExplicitUpdateAsync()
}

await (DbCleanupAsync());
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[0];
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = Array.Empty<IPostUpdateEventListener>();
}

[Test]
Expand Down Expand Up @@ -123,7 +124,7 @@ public async Task WithDetachedObjectAsync()
}

await (DbCleanupAsync());
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[0];
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = Array.Empty<IPostUpdateEventListener>();
}

[Test]
Expand Down Expand Up @@ -163,7 +164,7 @@ public async Task UpdateDetachedObjectAsync()
}

await (DbCleanupAsync());
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[0];
((DebugSessionFactory) Sfi).EventListeners.PostUpdateEventListeners = Array.Empty<IPostUpdateEventListener>();
}

[Test]
Expand Down Expand Up @@ -202,7 +203,7 @@ public async Task UpdateDetachedObjectWithLockAsync()
}

await (DbCleanupAsync());
((DebugSessionFactory)Sfi).EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[0];
((DebugSessionFactory)Sfi).EventListeners.PostUpdateEventListeners = Array.Empty<IPostUpdateEventListener>();
}
private async Task DbCleanupAsync(CancellationToken cancellationToken = default(CancellationToken))
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/ExceptionsTest/NullQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NullQueryTestAsync : TestCase

protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/Legacy/FumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task CriteriaCollectionAsync()
Assert.IsTrue(b.MapComponent.Stringmap.Count == 2);

int none = (await (s.CreateCriteria(typeof(Fum))
.Add(Expression.In("FumString", new string[0]))
.Add(Expression.In("FumString", Array.Empty<string>()))
.ListAsync())).Count;
Assert.AreEqual(0, none);

Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.Test/Async/LinqBulkManipulation/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NHibernate.Test.LinqBulkManipulation
[TestFixture]
public class FixtureAsync : TestCase
{
protected override IList Mappings => new string[0];
protected override IList Mappings => Array.Empty<string>();

protected override void Configure(Cfg.Configuration configuration)
{
Expand Down Expand Up @@ -970,7 +970,7 @@ public async Task SimpleDeleteOnAnimalAsync()
using (var t = s.BeginTransaction())
{
// Get rid of FK which may fail the test
_doll.Friends = new Human[0];
_doll.Friends = Array.Empty<Human>();
await (s.UpdateAsync(_doll));
await (t.CommitAsync());
}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ public async Task DeleteOnJoinedSubclassAsync()
using (var t = s.BeginTransaction())
{
// Get rid of FK which may fail the test
_doll.Friends = new Human[0];
_doll.Friends = Array.Empty<Human>();
await (s.UpdateAsync(_doll));
await (t.CommitAsync());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//------------------------------------------------------------------------------


using System;
using System.Collections;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode;
Expand All @@ -21,7 +22,7 @@ public class FixtureByCodeAsync : FixtureAsync
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override string MappingsAssembly
Expand Down Expand Up @@ -63,4 +64,4 @@ private HbmMapping GetMappings()
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class EmptyMappingsFixtureAsync : TestCase
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH1421/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void WhenParameterListIsEmptyUsingQueryThenDoesNotTrowsNullReferenceExcep
using (var s = OpenSession())
{
var query = s.CreateQuery("from AnEntity a where a.id in (:myList)");
Assert.That(() => query.SetParameterList("myList", new long[0]).ListAsync(), Throws.Exception.Not.InstanceOf<NullReferenceException>());
Assert.That(() => query.SetParameterList("myList", Array.Empty<long>()).ListAsync(), Throws.Exception.Not.InstanceOf<NullReferenceException>());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH2166/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FixtureAsync: TestCase
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override HbmMapping GetMappings()
protected override void Configure(Configuration configuration)
{
base.Configure(configuration);
var existingListeners = (configuration.EventListeners.PostInsertEventListeners ?? new IPostInsertEventListener[0]).ToList();
var existingListeners = (configuration.EventListeners.PostInsertEventListeners ?? Array.Empty<IPostInsertEventListener>()).ToList();
// this evil listener uses the session to perform a few queries and causes an auto-flush to happen
existingListeners.Add(new CausesAutoflushListener());
configuration.EventListeners.PostInsertEventListeners = existingListeners.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override HbmMapping GetMappings()
protected override void Configure(Configuration configuration)
{
base.Configure(configuration);
var existingListeners = (configuration.EventListeners.PostUpdateEventListeners ?? new IPostUpdateEventListener[0]).ToList();
var existingListeners = (configuration.EventListeners.PostUpdateEventListeners ?? Array.Empty<IPostUpdateEventListener>()).ToList();
// this evil listener uses the session to perform a few queries and causes an auto-flush to happen
existingListeners.Add(new CausesAutoflushListener());
configuration.EventListeners.PostUpdateEventListeners = existingListeners.ToArray();
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH901/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//------------------------------------------------------------------------------


using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
Expand Down Expand Up @@ -118,7 +119,7 @@ public class FixtureByCodeAsync : FixtureBaseAsync
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override string MappingsAssembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Reflection;
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.Test.SecondLevelCacheTests;
using NSubstitute;
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/TestTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestTestCaseAsync : TestCase
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

private bool _failOnTearDown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//------------------------------------------------------------------------------


using System;
using System.Collections;
using System.Data.Common;
using NUnit.Framework;
Expand All @@ -21,7 +22,7 @@ public class TransactionNotificationFixtureAsync : TestCase
{
protected override IList Mappings
{
get { return new string[] {}; }
get { return Array.Empty<string>(); }
}

[Test]
Expand Down Expand Up @@ -99,4 +100,4 @@ public async Task ShouldNotifyAfterTransactionWithOwnConnectionAsync(bool usePre
Assert.That(interceptor.afterTransactionCompletionCalled, Is.EqualTo(1));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task ReadWriteZeroLenAsync()
using (ISession s = OpenSession())
{
BinaryBlobClass b = new BinaryBlobClass();
b.BinaryBlob = new byte[0];
b.BinaryBlob = Array.Empty<byte>();
savedId = await (s.SaveAsync(b));
await (s.FlushAsync());
}
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate.Test/Async/TypesTest/BinaryTypeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public async Task InsertZeroLengthAsync()
BinaryClass bcBinary = new BinaryClass();
bcBinary.Id = 1;

bcBinary.DefaultSize = new byte[0];
bcBinary.WithSize = new byte[0];
bcBinary.DefaultSize = Array.Empty<byte>();
bcBinary.WithSize = Array.Empty<byte>();

ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate.Test/BulkManipulation/BaseFixture.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using NHibernate.Hql.Ast.ANTLR;
using System.Collections.Generic;
Expand All @@ -13,7 +14,7 @@ public class BaseFixture: TestCase

protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

#endregion
Expand All @@ -38,4 +39,4 @@ public string GetSql(string query)
return qt.SQLString;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class DeleteOneToOneOrphansTestByCode : DeleteOneToOneOrphansTest
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override void AddMappings(Configuration configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode;
Expand Down Expand Up @@ -93,7 +94,7 @@ public class DeleteOneToOneOrphansTestByCode : DeleteOneToOneOrphansTest
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class DeleteOneToOneOrphansTestByCode : DeleteOneToOneOrphansTest
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override void AddMappings(Configuration configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
Expand Down Expand Up @@ -142,7 +143,7 @@ public class DeleteOneToOneOrphansTestByCode : DeleteOneToOneOrphansTest
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override void AddMappings(Configuration configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
Expand Down Expand Up @@ -95,7 +96,7 @@ public class DeleteOneToOneOrphansTestByCode : DeleteOneToOneOrphansTest
{
protected override IList Mappings
{
get { return new string[0]; }
get { return Array.Empty<string>(); }
}

protected override void AddMappings(Configuration configuration)
Expand Down
Loading