Skip to content

Commit 3f38ee9

Browse files
committed
Merge branch 'pr-297' into v2.0.2
2 parents 6302b20 + ffc2c19 commit 3f38ee9

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

src/FluentNHibernate.Testing/PersistenceModelTests/SeparateSubclassVisitorFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Linq;
42
using FluentNHibernate.Mapping;
53
using FluentNHibernate.Mapping.Providers;
@@ -13,13 +11,13 @@ namespace FluentNHibernate.Testing.PersistenceModelTests
1311
[TestFixture]
1412
public class SeparateSubclassVisitorFixture
1513
{
16-
private IList<IIndeterminateSubclassMappingProvider> providers;
14+
private IIndeterminateSubclassMappingProviderCollection providers;
1715
private ClassMapping fooMapping;
1816

1917
[SetUp]
2018
public void SetUp()
2119
{
22-
providers = new List<IIndeterminateSubclassMappingProvider>();
20+
providers = new IndeterminateSubclassMappingProviderCollection();
2321
}
2422

2523
[Test]

src/FluentNHibernate/FluentNHibernate.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@
425425
<Compile Include="Mapping\NaturalIdPart.cs" />
426426
<Compile Include="Mapping\Providers\IElementMappingProvider.cs" />
427427
<Compile Include="Mapping\Providers\IExternalComponentMappingProvider.cs" />
428+
<Compile Include="Mapping\Providers\IIndeterminateSubclassMappingProviderCollection.cs" />
428429
<Compile Include="Mapping\Providers\INaturalIdMappingProvider.cs" />
430+
<Compile Include="Mapping\Providers\IndeterminateSubclassMappingProviderCollection.cs" />
429431
<Compile Include="Mapping\Providers\INestedCompositeElementMappingProvider.cs" />
430432
<Compile Include="Mapping\Providers\IPropertyMappingProvider.cs" />
431433
<Compile Include="Mapping\Providers\IReferenceComponentMappingProvider.cs" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace FluentNHibernate.Mapping.Providers
5+
{
6+
public interface IIndeterminateSubclassMappingProviderCollection : IEnumerable<IIndeterminateSubclassMappingProvider>
7+
{
8+
void Add(IIndeterminateSubclassMappingProvider item);
9+
bool IsTypeMapped(Type type);
10+
}
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace FluentNHibernate.Mapping.Providers
6+
{
7+
/// <summary>
8+
/// This collection optimizes search for already mapped types in subclasses providers. Matters in models with huge inheritance trees.
9+
/// </summary>
10+
public class IndeterminateSubclassMappingProviderCollection : IIndeterminateSubclassMappingProviderCollection
11+
{
12+
private readonly List<IIndeterminateSubclassMappingProvider> providers = new List<IIndeterminateSubclassMappingProvider>();
13+
private readonly HashSet<Type> mappedTypes = new HashSet<Type>();
14+
15+
public IEnumerator<IIndeterminateSubclassMappingProvider> GetEnumerator()
16+
{
17+
return providers.GetEnumerator();
18+
}
19+
20+
IEnumerator IEnumerable.GetEnumerator()
21+
{
22+
return GetEnumerator();
23+
}
24+
25+
public void Add(IIndeterminateSubclassMappingProvider item)
26+
{
27+
providers.Add(item);
28+
mappedTypes.Add(item.EntityType);
29+
}
30+
31+
public bool IsTypeMapped(Type type)
32+
{
33+
return mappedTypes.Contains(type);
34+
}
35+
}
36+
}

src/FluentNHibernate/PersistenceModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PersistenceModel
2424
{
2525
protected readonly IList<IMappingProvider> classProviders = new List<IMappingProvider>();
2626
protected readonly IList<IFilterDefinition> filterDefinitions = new List<IFilterDefinition>();
27-
protected readonly IList<IIndeterminateSubclassMappingProvider> subclassProviders = new List<IIndeterminateSubclassMappingProvider>();
27+
protected readonly IIndeterminateSubclassMappingProviderCollection subclassProviders = new IndeterminateSubclassMappingProviderCollection();
2828
protected readonly IList<IExternalComponentMappingProvider> componentProviders = new List<IExternalComponentMappingProvider>();
2929
protected readonly IList<IComponentReferenceResolver> componentResolvers = new List<IComponentReferenceResolver>
3030
{

src/FluentNHibernate/Visitors/SeparateSubclassVisitor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace FluentNHibernate.Visitors
99
{
1010
public class SeparateSubclassVisitor : DefaultMappingModelVisitor
1111
{
12-
private readonly IList<IIndeterminateSubclassMappingProvider> subclassProviders;
12+
private readonly IIndeterminateSubclassMappingProviderCollection subclassProviders;
1313

14-
public SeparateSubclassVisitor(IList<IIndeterminateSubclassMappingProvider> subclassProviders)
14+
public SeparateSubclassVisitor(IIndeterminateSubclassMappingProviderCollection subclassProviders)
1515
{
1616
this.subclassProviders = subclassProviders;
1717
}
@@ -65,9 +65,9 @@ private SubclassType GetSubclassType(ClassMapping mapping)
6565
return SubclassType.Subclass;
6666
}
6767

68-
private bool IsMapped(Type type, IEnumerable<IIndeterminateSubclassMappingProvider> providers)
68+
private bool IsMapped(Type type, IIndeterminateSubclassMappingProviderCollection providers)
6969
{
70-
return providers.Any(x => x.EntityType == type);
70+
return providers.IsTypeMapped(type);
7171
}
7272

7373
/// <summary>

0 commit comments

Comments
 (0)