Skip to content

Commit cf041df

Browse files
committed
Reuse the same generic EmptyMapClass instance across the project
1 parent 73797df commit cf041df

18 files changed

+34
-23
lines changed

src/NHibernate/Cfg/MappingSchema/AbstractDecoratable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NHibernate.Cfg.MappingSchema
99
[Serializable]
1010
public abstract class AbstractDecoratable : IDecoratable
1111
{
12-
private static readonly IDictionary<string, MetaAttribute> EmptyMetaData = new CollectionHelper.EmptyMapClass<string, MetaAttribute>();
12+
private static readonly IDictionary<string, MetaAttribute> EmptyMetaData = CollectionHelper.EmptyDictionary<string, MetaAttribute>();
1313

1414
[NonSerialized]
1515
[XmlIgnore]

src/NHibernate/Cfg/XmlHbmBinding/Binder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class Binder
1313
protected static readonly INHibernateLogger log = NHibernateLogger.For(typeof (Binder));
1414

1515
protected static readonly IDictionary<string, MetaAttribute> EmptyMeta =
16-
new CollectionHelper.EmptyMapClass<string, MetaAttribute>();
16+
CollectionHelper.EmptyDictionary<string, MetaAttribute>();
1717

1818
protected readonly Mappings mappings;
1919

src/NHibernate/Cfg/XmlHbmBinding/ResultSetMappingBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private IDictionary<string, string[]> BindPropertyResults(string alias, HbmRetur
309309
{
310310
newPropertyResults[entry.Key] = entry.Value;
311311
}
312-
return newPropertyResults.Count == 0 ? (IDictionary<string, string[]>)new CollectionHelper.EmptyMapClass<string, string[]>() : newPropertyResults;
312+
return newPropertyResults.Count == 0 ? (IDictionary<string, string[]>)CollectionHelper.EmptyDictionary<string, string[]>() : newPropertyResults;
313313
}
314314

315315
private static List<string> GetResultColumns(HbmReturnProperty returnPropertySchema)

src/NHibernate/Engine/JoinSequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public JoinSequence AddJoin(IAssociationType associationType, string alias, Join
128128

129129
public JoinFragment ToJoinFragment()
130130
{
131-
return ToJoinFragment(new CollectionHelper.EmptyMapClass<string, IFilter>(), true);
131+
return ToJoinFragment(CollectionHelper.EmptyDictionary<string, IFilter>(), true);
132132
}
133133

134134
public JoinFragment ToJoinFragment(IDictionary<string, IFilter> enabledFilters, bool includeExtraJoins)

src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private void PostProcessDML(IRestrictableStatement statement)
393393
if (persister.DiscriminatorType != null)
394394
{
395395
new SyntheticAndFactory(this)
396-
.AddDiscriminatorWhereFragment(statement, persister, new CollectionHelper.EmptyMapClass<string, IFilter>(), fromElement.TableAlias);
396+
.AddDiscriminatorWhereFragment(statement, persister, CollectionHelper.EmptyDictionary<string, IFilter>(), fromElement.TableAlias);
397397
}
398398
}
399399

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,15 @@ public string GetIdentifierPropertyName(string className)
616616
public IType[] GetReturnTypes(String queryString)
617617
{
618618
return
619-
queryPlanCache.GetHQLQueryPlan(queryString.ToQueryExpression(), false, new CollectionHelper.EmptyMapClass<string, IFilter>()).
619+
queryPlanCache.GetHQLQueryPlan(queryString.ToQueryExpression(), false, CollectionHelper.EmptyDictionary<string, IFilter>()).
620620
ReturnMetadata.ReturnTypes;
621621
}
622622

623623
/// <summary> Get the return aliases of a query</summary>
624624
public string[] GetReturnAliases(string queryString)
625625
{
626626
return
627-
queryPlanCache.GetHQLQueryPlan(queryString.ToQueryExpression(), false, new CollectionHelper.EmptyMapClass<string, IFilter>()).
627+
queryPlanCache.GetHQLQueryPlan(queryString.ToQueryExpression(), false, CollectionHelper.EmptyDictionary<string, IFilter>()).
628628
ReturnMetadata.ReturnAliases;
629629
}
630630

@@ -1163,7 +1163,7 @@ private IDictionary<string, HibernateException> CheckNamedQueries()
11631163
{
11641164
log.Debug("Checking named query: {0}", queryName);
11651165
//TODO: BUG! this currently fails for named queries for non-POJO entities
1166-
queryPlanCache.GetHQLQueryPlan(qd.QueryString.ToQueryExpression(), false, new CollectionHelper.EmptyMapClass<string, IFilter>());
1166+
queryPlanCache.GetHQLQueryPlan(qd.QueryString.ToQueryExpression(), false, CollectionHelper.EmptyDictionary<string, IFilter>());
11671167
}
11681168
catch (QueryException e)
11691169
{

src/NHibernate/Impl/SqlQueryImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected internal override IDictionary<string, LockMode> LockModes
9393
get
9494
{
9595
//we never need to apply locks to the SQL
96-
return new CollectionHelper.EmptyMapClass<string, LockMode>();
96+
return CollectionHelper.EmptyDictionary<string, LockMode>();
9797
}
9898
}
9999

@@ -236,7 +236,7 @@ public ISQLQuery AddJoin(string alias, string path, LockMode lockMode)
236236
string ownerAlias = path.Substring(0, loc);
237237
string role = path.Substring(loc + 1);
238238
queryReturns.Add(
239-
new NativeSQLQueryJoinReturn(alias, ownerAlias, role, new CollectionHelper.EmptyMapClass<string, string[]>(), lockMode));
239+
new NativeSQLQueryJoinReturn(alias, ownerAlias, role, CollectionHelper.EmptyDictionary<string, string[]>(), lockMode));
240240
return this;
241241
}
242242

src/NHibernate/Impl/StatelessSessionImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public override IType GetFilterParameterType(string filterParameterName)
288288

289289
public override IDictionary<string, IFilter> EnabledFilters
290290
{
291-
get { return new CollectionHelper.EmptyMapClass<string, IFilter>(); }
291+
get { return CollectionHelper.EmptyDictionary<string, IFilter>(); }
292292
}
293293

294294
public override IQueryTranslator[] GetQueries(IQueryExpression query, bool scalar)

src/NHibernate/Loader/AbstractEntityJoinWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected virtual void InitAll(SqlString whereString, SqlString orderByString, L
3333
IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
3434
allAssociations.Add(
3535
new OuterJoinableAssociation(persister.EntityType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
36-
new CollectionHelper.EmptyMapClass<string, IFilter>()));
36+
CollectionHelper.EmptyDictionary<string, IFilter>()));
3737

3838
InitPersisters(allAssociations, lockMode);
3939
InitStatementString(whereString, orderByString, lockMode);

src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public OneToManyJoinWalker(IQueryableCollection oneToManyPersister, int batchSiz
3838
IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
3939
allAssociations.Add(
4040
new OuterJoinableAssociation(oneToManyPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
41-
new CollectionHelper.EmptyMapClass<string, IFilter>()));
41+
CollectionHelper.EmptyDictionary<string, IFilter>()));
4242

4343
InitPersisters(allAssociations, LockMode.None);
4444
InitStatementString(elementPersister, alias, batchSize, subquery);

src/NHibernate/Loader/DefaultEntityAliases.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DefaultEntityAliases : IEntityAliases
1919
private readonly IDictionary<string, string[]> userProvidedAliases;
2020

2121
public DefaultEntityAliases(ILoadable persister, string suffix)
22-
: this(new CollectionHelper.EmptyMapClass<string, string[]>(), persister, suffix) {}
22+
: this(CollectionHelper.EmptyDictionary<string, string[]>(), persister, suffix) {}
2323

2424
/// <summary>
2525
/// Calculate and cache select-clause suffixes.
@@ -147,4 +147,4 @@ private static void Intern(string[] strings)
147147
}
148148
}
149149
}
150-
}
150+
}

src/NHibernate/Loader/Entity/CascadeEntityJoinWalker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public class CascadeEntityJoinWalker : AbstractEntityJoinWalker
1212

1313
public CascadeEntityJoinWalker(IOuterJoinLoadable persister, CascadingAction action,
1414
ISessionFactoryImplementor factory)
15-
: base(persister, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
15+
: base(persister, factory, CollectionHelper.EmptyDictionary<string, IFilter>())
1616
{
1717
cascadeAction = action;
1818
SqlStringBuilder whereCondition = WhereString(Alias, persister.IdentifierColumnNames, 1)
1919
//include the discriminator and class-level where, but not filters
20-
.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));
20+
.Add(persister.FilterFragment(Alias, CollectionHelper.EmptyDictionary<string, IFilter>()));
2121

2222
InitAll(whereCondition.ToSqlString(), SqlString.Empty, LockMode.Read);
2323
}

src/NHibernate/Loader/Entity/CascadeEntityLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NHibernate.Loader.Entity
77
public class CascadeEntityLoader : AbstractEntityLoader
88
{
99
public CascadeEntityLoader(IOuterJoinLoadable persister, CascadingAction action, ISessionFactoryImplementor factory)
10-
: base(persister, persister.IdentifierType, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
10+
: base(persister, persister.IdentifierType, factory, CollectionHelper.EmptyDictionary<string, IFilter>())
1111
{
1212
JoinWalker walker = new CascadeEntityJoinWalker(persister, action, factory);
1313
InitFromWalker(walker);

src/NHibernate/Loader/Entity/EntityJoinWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public EntityJoinWalker(IOuterJoinLoadable persister, string[] uniqueKey, int ba
2323

2424
SqlStringBuilder whereCondition = WhereString(Alias, uniqueKey, batchSize)
2525
//include the discriminator and class-level where, but not filters
26-
.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));
26+
.Add(persister.FilterFragment(Alias, CollectionHelper.EmptyDictionary<string, IFilter>()));
2727

2828
InitAll(whereCondition.ToSqlString(), SqlString.Empty, lockMode);
2929
}

src/NHibernate/Loader/GeneratedCollectionAliases.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public GeneratedCollectionAliases(IDictionary<string, string[]> userProvidedAlia
3737
}
3838

3939
public GeneratedCollectionAliases(ICollectionPersister persister, string str)
40-
: this(new CollectionHelper.EmptyMapClass<string, string[]>(), persister, str) {}
40+
: this(CollectionHelper.EmptyDictionary<string, string[]>(), persister, str) {}
4141

4242
private string[] GetUserProvidedCompositeElementAliases(string[] defaultAliases)
4343
{

src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurre
559559
public void PostInstantiate()
560560
{
561561
initializer = queryLoaderName == null
562-
? CreateCollectionInitializer(new CollectionHelper.EmptyMapClass<string, IFilter>())
562+
? CreateCollectionInitializer(CollectionHelper.EmptyDictionary<string, IFilter>())
563563
: new NamedQueryCollectionInitializer(queryLoaderName, this);
564564
}
565565

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ protected void CreateUniqueKeyLoaders()
21182118
//don't need filters for the static loaders
21192119
uniqueKeyLoaders[propertyNames[i]] =
21202120
CreateUniqueKeyLoader(propertyTypes[i], GetPropertyColumnNames(i),
2121-
new CollectionHelper.EmptyMapClass<string, IFilter>());
2121+
CollectionHelper.EmptyDictionary<string, IFilter>());
21222122
}
21232123
}
21242124
}
@@ -2197,7 +2197,7 @@ protected IUniqueEntityLoader CreateEntityLoader(LockMode lockMode, IDictionary<
21972197

21982198
protected IUniqueEntityLoader CreateEntityLoader(LockMode lockMode)
21992199
{
2200-
return CreateEntityLoader(lockMode, new CollectionHelper.EmptyMapClass<string, IFilter>());
2200+
return CreateEntityLoader(lockMode, CollectionHelper.EmptyDictionary<string, IFilter>());
22012201
}
22022202

22032203
protected bool Check(int rows, object id, int tableNumber, IExpectation expectation, DbCommand statement)

src/NHibernate/Util/CollectionHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ public IEnumerator GetEnumerator()
214214

215215
public static readonly IEnumerable EmptyEnumerable = new EmptyEnumerableClass();
216216
public static readonly IDictionary EmptyMap = new EmptyMapClass();
217+
218+
public static IDictionary<TKey, TValue> EmptyDictionary<TKey, TValue>()
219+
{
220+
return EmptyDictionaryHolder<TKey, TValue>.Instance;
221+
}
222+
217223
public static readonly ICollection EmptyCollection = EmptyMap;
218224
// Since v5
219225
[Obsolete("It has no more usages in NHibernate and will be removed in a future version.")]
@@ -457,6 +463,11 @@ public object Current
457463
#endregion
458464
}
459465

466+
private static class EmptyDictionaryHolder<TKey, TValue>
467+
{
468+
public static readonly EmptyMapClass<TKey, TValue> Instance = new EmptyMapClass<TKey, TValue>();
469+
}
470+
460471
/// <summary>
461472
/// A read-only dictionary that is always empty and permits lookup by <see langword="null" /> key.
462473
/// </summary>

0 commit comments

Comments
 (0)