Skip to content
Browse files

Optimize access to dictionaries across all code.

  • Loading branch information...
1 parent 00a5902 commit 3fb22c98dde4801d1cfe70d03b5b23157feb857b @hazzik hazzik committed Sep 30, 2012
View
10 src/NHibernate/Cfg/Configuration.cs
@@ -312,7 +312,9 @@ public PersistentClass GetClassMapping(string entityName)
/// <returns><see cref="NHibernate.Mapping.Collection" /></returns>
public NHibernate.Mapping.Collection GetCollectionMapping(string role)
{
- return collections.ContainsKey(role) ? collections[role] : null;
+ NHibernate.Mapping.Collection result;
+ collections.TryGetValue(role, out result);
+ return result;
}
/// <summary>
@@ -1291,12 +1293,12 @@ public IInterceptor Interceptor
if (Properties.ContainsKey(Environment.Dialect))
{
- Dialect.Dialect dialect = Dialect.Dialect.GetDialect(Properties);
- foreach (KeyValuePair<string, string> pair in dialect.DefaultProperties)
+ var dialect = Dialect.Dialect.GetDialect(Properties);
+ foreach (var pair in dialect.DefaultProperties)
derivedProperties[pair.Key] = pair.Value;
}
- foreach (KeyValuePair<string, string> pair in Properties)
+ foreach (var pair in Properties)
derivedProperties[pair.Key] = pair.Value;
return derivedProperties;
View
22 src/NHibernate/Cfg/Environment.cs
@@ -231,27 +231,21 @@ private static void LoadGlobalPropertiesFromAppConfig()
GlobalProperties[PropertyUseReflectionOptimizer] = nhConfig.UseReflectionOptimizer.ToString();
if (nhConfig.SessionFactory != null)
{
- foreach (KeyValuePair<string, string> kvp in nhConfig.SessionFactory.Properties)
+ foreach (var kvp in nhConfig.SessionFactory.Properties)
{
GlobalProperties[kvp.Key] = kvp.Value;
}
}
}
internal static void ResetSessionFactoryProperties()
- {
- string savedBytecodeProvider = null;
- string savedUseReflectionOptimizer = null;
-
- // Save values loaded and used in static constructor
- if (GlobalProperties.ContainsKey(PropertyBytecodeProvider))
- {
- savedBytecodeProvider = GlobalProperties[PropertyBytecodeProvider];
- }
- if (GlobalProperties.ContainsKey(PropertyUseReflectionOptimizer))
- {
- savedUseReflectionOptimizer = GlobalProperties[PropertyUseReflectionOptimizer];
- }
+ {
+ string savedBytecodeProvider;
+ GlobalProperties.TryGetValue(PropertyBytecodeProvider, out savedBytecodeProvider);
+ // Save values loaded and used in static constructor
+
+ string savedUseReflectionOptimizer;
+ GlobalProperties.TryGetValue(PropertyUseReflectionOptimizer, out savedUseReflectionOptimizer);
// Clean all property loaded from app.config
GlobalProperties.Clear();
View
18 src/NHibernate/Collection/Generic/PersistentGenericMap.cs
@@ -51,8 +51,8 @@ public override void BeforeInitialize(ICollectionPersister persister, int antici
public override IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula)
{
IList deletes = new List<object>();
- IDictionary<TKey, TValue> sn = (IDictionary<TKey, TValue>)GetSnapshot();
- foreach (KeyValuePair<TKey, TValue> e in sn)
+ var sn = (IDictionary<TKey, TValue>)GetSnapshot();
+ foreach (var e in sn)
{
if (!gmap.ContainsKey(e.Key))
{
@@ -65,17 +65,17 @@ public override IEnumerable GetDeletes(ICollectionPersister persister, bool inde
public override bool NeedsInserting(object entry, int i, IType elemType)
{
- IDictionary sn = (IDictionary)GetSnapshot();
- KeyValuePair<TKey, TValue> e = (KeyValuePair<TKey, TValue>)entry;
+ var sn = (IDictionary)GetSnapshot();
+ var e = (KeyValuePair<TKey, TValue>)entry;
return !sn.Contains(e.Key);
}
public override bool NeedsUpdating(object entry, int i, IType elemType)
{
- IDictionary sn = (IDictionary)GetSnapshot();
- KeyValuePair<TKey, TValue> e = (KeyValuePair<TKey, TValue>)entry;
- object snValue = sn[e.Key];
- bool isNew = !sn.Contains(e.Key);
+ var sn = (IDictionary)GetSnapshot();
+ var e = (KeyValuePair<TKey, TValue>)entry;
+ var snValue = sn[e.Key];
+ var isNew = !sn.Contains(e.Key);
return e.Value != null && snValue != null && elemType.IsDirty(snValue, e.Value, Session)
|| (!isNew && ((e.Value == null) != (snValue == null)));
}
@@ -92,7 +92,7 @@ public override object GetElement(object entry)
public override object GetSnapshotElement(object entry, int i)
{
- IDictionary sn = (IDictionary)GetSnapshot();
+ var sn = (IDictionary)GetSnapshot();
return sn[((KeyValuePair<TKey, TValue>)entry).Key];
}
View
14 src/NHibernate/Context/ThreadLocalSessionContext.cs
@@ -125,9 +125,8 @@ private static ISession DoUnbind(ISessionFactory factory, bool releaseMapIfEmpty
if (context != null)
{
- if (context.ContainsKey(factory))
+ if (context.TryGetValue(factory, out session))
{
- session = context[factory];
context.Remove(factory);
}
@@ -175,13 +174,10 @@ private static ISession ExistingSession(ISessionFactory factory)
{
if (context == null)
return null;
- else
- {
- if (context.ContainsKey(factory))
- return context[factory];
- else
- return null;
- }
+
+ ISession result;
+ context.TryGetValue(factory, out result);
+ return result;
}
}
}
View
8 src/NHibernate/Dialect/Function/SQLFunctionRegistry.cs
@@ -17,14 +17,12 @@ public SQLFunctionRegistry(Dialect dialect, IDictionary<string, ISQLFunction> us
public ISQLFunction FindSQLFunction(string functionName)
{
- if (userFunctions.ContainsKey(functionName))
- return userFunctions[functionName];
- else
+ ISQLFunction result;
+ if (!userFunctions.TryGetValue(functionName, out result))
{
- ISQLFunction result;
dialect.Functions.TryGetValue(functionName, out result);
- return result;
}
+ return result;
}
public bool HasFunction(string functionName)
View
27 src/NHibernate/Dialect/MsSql2005DialectQueryPager.cs
@@ -156,11 +156,12 @@ private static void AppendSortExpressions(Dictionary<SqlString, SqlString> alias
}
SqlString sortExpression = RemoveSortOrderDirection(sortExpressions[i]);
- if (aliasToColumn.ContainsKey(sortExpression))
+ SqlString s;
+ if (aliasToColumn.TryGetValue(sortExpression, out s))
{
- result.Add(aliasToColumn[sortExpression]);
+ result.Add(s);
}
- else
+ else
{
result.Add(sortExpression);
}
@@ -196,16 +197,20 @@ private static void AppendSortExpressionsForDistinct(Dictionary<SqlString, SqlSt
if (sortExpression.StartsWithCaseInsensitive("CURRENT_TIMESTAMP"))
result.Add(sortExpression);
- else if (columnToAlias.ContainsKey(sortExpression))
- {
- result.Add("q_.");
- result.Add(columnToAlias[sortExpression]);
- }
else
{
- throw new HibernateException(
- "The dialect was unable to perform paging of a statement that requires distinct results, and "
- + "is ordered by a column that is not included in the result set of the query.");
+ SqlString value;
+ if (columnToAlias.TryGetValue(sortExpression, out value))
+ {
+ result.Add("q_.");
+ result.Add(value);
+ }
+ else
+ {
+ throw new HibernateException(
+ "The dialect was unable to perform paging of a statement that requires distinct results, and "
+ + "is ordered by a column that is not included in the result set of the query.");
+ }
}
if (sortExpressions[i].Trim().EndsWithCaseInsensitive("desc"))
View
11 src/NHibernate/Driver/NDataReader.cs
@@ -593,12 +593,11 @@ public int GetOrdinal(string colName)
// null, perform a case-insensitive search (as being described in the IDataRecord
// interface, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataIDataRecordClassItemTopic1.asp.
// This is necessary for databases that don't preserve the case of field names when
- // they are created without quotes (e.g. DB2, PostgreSQL).
- if (fieldNameToIndex.ContainsKey(colName))
- {
- return fieldNameToIndex[colName];
- }
-
+ // they are created without quotes (e.g. DB2, PostgreSQL).
+ int value;
+ if (fieldNameToIndex.TryGetValue(colName, out value))
+ return value;
+
foreach (KeyValuePair<string, int> pair in fieldNameToIndex)
{
if (StringHelper.EqualsCaseInsensitive(pair.Key, colName))
View
2 src/NHibernate/Hql/Ast/ANTLR/CollectionProperties.cs
@@ -44,7 +44,7 @@ public static bool IsCollectionProperty(string name)
public static string GetNormalizedPropertyName(string name)
{
- return (string)HQL_COLLECTION_PROPERTIES[name];
+ return HQL_COLLECTION_PROPERTIES[name];
}
public static bool IsAnyCollectionProperty(string name)
View
13 src/NHibernate/Hql/Ast/ANTLR/Tree/FromClause.cs
@@ -104,12 +104,15 @@ public bool IsFromElementAlias(string possibleAlias)
/// <returns>true if the from node contains the class alias name.</returns>
public bool ContainsClassAlias(string alias)
{
- bool isAlias = _fromElementByClassAlias.ContainsKey(alias);
- if (!isAlias && SessionFactoryHelper.IsStrictJPAQLComplianceEnabled)
+ if (_fromElementByClassAlias.ContainsKey(alias))
{
- isAlias = FindIntendedAliasedFromElementBasedOnCrazyJPARequirements(alias) != null;
+ return true;
}
- return isAlias;
+ if (SessionFactoryHelper.IsStrictJPAQLComplianceEnabled)
+ {
+ return FindIntendedAliasedFromElementBasedOnCrazyJPARequirements(alias) != null;
+ }
+ return false;
}
/// <summary>
@@ -270,7 +273,7 @@ private void CheckForDuplicateClassAlias(string classAlias)
private static bool ProjectionListPredicate(IASTNode node)
{
- FromElement fromElement = node as FromElement;
+ var fromElement = node as FromElement;
if (fromElement != null)
{
View
60 src/NHibernate/Impl/ExpressionProcessor.cs
@@ -236,23 +236,24 @@ public static ProjectionInfo FindMemberProjection(Expression expression)
if (!IsMemberExpression(expression))
return ProjectionInfo.ForProjection(Projections.Constant(FindValue(expression)));
- if (expression is UnaryExpression)
+ var unaryExpression = expression as UnaryExpression;
+ if (unaryExpression != null)
{
- UnaryExpression unaryExpression = (UnaryExpression)expression;
-
if (!IsConversion(unaryExpression.NodeType))
- throw new Exception("Cannot interpret member from " + expression.ToString());
+ throw new Exception("Cannot interpret member from " + expression);
return FindMemberProjection(unaryExpression.Operand);
}
- if (expression is MethodCallExpression)
+ var methodCallExpression = expression as MethodCallExpression;
+ if (methodCallExpression != null)
{
- MethodCallExpression methodCallExpression = (MethodCallExpression)expression;
-
- string signature = Signature(methodCallExpression.Method);
- if (_customProjectionProcessors.ContainsKey(signature))
- return ProjectionInfo.ForProjection(_customProjectionProcessors[signature](methodCallExpression));
+ var signature = Signature(methodCallExpression.Method);
+ Func<MethodCallExpression, IProjection> processor;
+ if (_customProjectionProcessors.TryGetValue(signature, out processor))
+ {
+ return ProjectionInfo.ForProjection(processor(methodCallExpression));
+ }
}
return ProjectionInfo.ForProperty(FindMemberExpression(expression));
@@ -416,10 +417,9 @@ private static bool IsMemberExpression(Expression expression)
return IsMemberExpression(unaryExpression.Operand);
}
- if (expression is MethodCallExpression)
+ var methodCallExpression = expression as MethodCallExpression;
+ if (methodCallExpression != null)
{
- MethodCallExpression methodCallExpression = (MethodCallExpression)expression;
-
string signature = Signature(methodCallExpression.Method);
if (_customProjectionProcessors.ContainsKey(signature))
return true;
@@ -495,12 +495,11 @@ private static ICriterion ProcessSimpleExpression(Expression left, Expression ri
if (value == null)
return ProcessSimpleNullExpression(property, nodeType);
- if (!_simpleExpressionCreators.ContainsKey(nodeType))
+ Func<ProjectionInfo, object, ICriterion> simpleExpressionCreator;
+ if (!_simpleExpressionCreators.TryGetValue(nodeType, out simpleExpressionCreator))
throw new Exception("Unhandled simple expression type: " + nodeType);
- Func<ProjectionInfo, object, ICriterion> simpleExpressionCreator = _simpleExpressionCreators[nodeType];
- ICriterion criterion = simpleExpressionCreator(property, value);
- return criterion;
+ return simpleExpressionCreator(property, value);
}
private static ICriterion ProcessVisualBasicStringComparison(BinaryExpression be)
@@ -535,12 +534,11 @@ private static ICriterion ProcessMemberExpression(Expression left, Expression ri
ProjectionInfo leftProperty = FindMemberProjection(left);
ProjectionInfo rightProperty = FindMemberProjection(right);
- if (!_propertyExpressionCreators.ContainsKey(nodeType))
+ Func<ProjectionInfo, ProjectionInfo, ICriterion> propertyExpressionCreator;
+ if (!_propertyExpressionCreators.TryGetValue(nodeType, out propertyExpressionCreator))
throw new Exception("Unhandled property expression type: " + nodeType);
- Func<ProjectionInfo, ProjectionInfo, ICriterion> propertyExpressionCreator = _propertyExpressionCreators[nodeType];
- ICriterion criterion = propertyExpressionCreator(leftProperty, rightProperty);
- return criterion;
+ return propertyExpressionCreator(leftProperty, rightProperty);
}
private static ICriterion ProcessAndExpression(BinaryExpression expression)
@@ -641,20 +639,20 @@ private static ICriterion ProcessCustomMethodCall(MethodCallExpression methodCal
{
string signature = Signature(methodCallExpression.Method);
- if (!_customMethodCallProcessors.ContainsKey(signature))
+ Func<MethodCallExpression, ICriterion> customMethodCallProcessor;
+ if (!_customMethodCallProcessors.TryGetValue(signature, out customMethodCallProcessor))
throw new Exception("Unrecognised method call: " + signature);
- Func<MethodCallExpression, ICriterion> customMethodCallProcessor = _customMethodCallProcessors[signature];
- ICriterion criterion = customMethodCallProcessor(methodCallExpression);
- return criterion;
+ return customMethodCallProcessor(methodCallExpression);
}
private static ICriterion ProcessExpression(Expression expression)
{
- if (expression is BinaryExpression)
- return ProcessBinaryExpression((BinaryExpression)expression);
- else
- return ProcessBooleanExpression((Expression)expression);
+ var binaryExpression = expression as BinaryExpression;
+ if (binaryExpression != null)
+ return ProcessBinaryExpression(binaryExpression);
+
+ return ProcessBooleanExpression(expression);
}
private static ICriterion ProcessLambdaExpression(LambdaExpression expression)
@@ -750,10 +748,10 @@ public static ICriterion ProcessExpression(Expression<Func<bool>> expression)
var subqueryExpressionCreators = _subqueryExpressionCreatorTypes[subqueryType];
- if (!subqueryExpressionCreators.ContainsKey(be.NodeType))
+ Func<string, DetachedCriteria, AbstractCriterion> subqueryExpressionCreator;
+ if (!subqueryExpressionCreators.TryGetValue(be.NodeType, out subqueryExpressionCreator))
throw new Exception("Unhandled subquery expression type: " + subqueryType + "," + be.NodeType);
- Func<string, DetachedCriteria, AbstractCriterion> subqueryExpressionCreator = subqueryExpressionCreators[be.NodeType];
return subqueryExpressionCreator(property, detachedCriteria);
}
View
8 src/NHibernate/Impl/FilterImpl.cs
@@ -129,11 +129,9 @@ public object GetParameter(string name)
public void Validate()
{
foreach (string parameterName in definition.ParameterNames)
- {
- if (!parameters.ContainsKey(parameterName))
- {
- throw new HibernateException("Filter [" + Name + "] parameter [" + parameterName + "] value not set");
- }
+ {
+ if (!parameters.ContainsKey(parameterName))
+ throw new HibernateException(string.Format("Filter [{0}] parameter [{1}] value not set", Name, parameterName));
}
}
}
View
9 src/NHibernate/Impl/MultiCriteriaImpl.cs
@@ -414,12 +414,11 @@ public object GetResult(string key)
{
if (criteriaResults == null) List();
- if (!criteriaResultPositions.ContainsKey(key))
- {
+ int criteriaResultPosition;
+ if (!criteriaResultPositions.TryGetValue(key, out criteriaResultPosition))
throw new InvalidOperationException(String.Format("The key '{0}' is unknown", key));
- }
- return criteriaResults[criteriaResultPositions[key]];
+ return criteriaResults[criteriaResultPosition];
}
#endregion
@@ -456,9 +455,7 @@ private QueryParameters CreateCombinedQueryParameters()
private void ThrowIfKeyAlreadyExists(string key)
{
if (criteriaResultPositions.ContainsKey(key))
- {
throw new InvalidOperationException(String.Format("The key '{0}' already exists", key));
- }
}
}
}
View
9 src/NHibernate/Impl/MultiQueryImpl.cs
@@ -654,12 +654,11 @@ public object GetResult(string key)
queryResults = List();
}
- if (!queryResultPositions.ContainsKey(key))
- {
+ int queryResultPosition;
+ if (!queryResultPositions.TryGetValue(key, out queryResultPosition))
throw new InvalidOperationException(String.Format("The key '{0}' is unknown", key));
- }
- return queryResults[queryResultPositions[key]];
+ return queryResults[queryResultPosition];
}
public override string ToString()
@@ -764,9 +763,7 @@ private IList<QueryParameters> Parameters
private void ThrowIfKeyAlreadyExists(string key)
{
if (queryResultPositions.ContainsKey(key))
- {
throw new InvalidOperationException(String.Format("The key '{0}' already exists", key));
- }
}
private int AddQueryForLaterExecutionAndReturnIndexOfQuery(System.Type resultGenericListType, IQuery query)
View
3 src/NHibernate/Impl/SessionImpl.cs
@@ -2315,8 +2315,7 @@ public ISession GetSession(EntityMode entityMode)
}
else
{
- if (childSessionsByEntityMode.ContainsKey(entityMode))
- rtn = childSessionsByEntityMode[entityMode];
+ childSessionsByEntityMode.TryGetValue(entityMode, out rtn);
}
if (rtn == null)
View
13 src/NHibernate/Linq/QuerySourceNamer.cs
@@ -24,14 +24,17 @@ public void Add(IQuerySource querySource)
public string GetName(IQuerySource querySource)
{
- if (!_map.ContainsKey(querySource))
+ string result;
+ if (!_map.TryGetValue(querySource, out result))
+ {
throw new HibernateException(
String.Format("Query Source could not be identified: ItemName = {0}, ItemType = {1}, Expression = {2}",
- querySource.ItemName,
- querySource.ItemType,
- querySource));
+ querySource.ItemName,
+ querySource.ItemType,
+ querySource));
+ }
- return _map[querySource];
+ return result;
}
private string CreateUniqueName(string proposedName)
View
5 src/NHibernate/Linq/Visitors/JoinBuilder.cs
@@ -50,9 +50,10 @@ public void MakeInnerIfJoined(string key)
{
// key is not joined if it occurs only at tails of expressions, e.g.
// a.B == null, a.B != null, a.B == c.D etc.
- if (_joins.ContainsKey(key))
+ NhJoinClause nhJoinClause;
+ if (_joins.TryGetValue(key, out nhJoinClause))
{
- _joins[key].MakeInner();
+ nhJoinClause.MakeInner();
}
}
View
5 src/NHibernate/Linq/Visitors/WhereJoinDetector.cs
@@ -375,8 +375,9 @@ public ExpressionValues(PossibleValueSet valuesIfUnknownMemberExpression)
public PossibleValueSet GetValues(string memberExpression)
{
- if (MemberExpressionValuesIfEmptyOuterJoined.ContainsKey(memberExpression))
- return MemberExpressionValuesIfEmptyOuterJoined[memberExpression];
+ PossibleValueSet value;
+ if (MemberExpressionValuesIfEmptyOuterJoined.TryGetValue(memberExpression, out value))
+ return value;
return Values;
}
View
25 src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs
@@ -249,13 +249,8 @@ public JoinType GetJoinType(string path)
{
JoinType result;
if (associationPathJoinTypesMap.TryGetValue(path, out result))
- {
return result;
- }
- else
- {
- return JoinType.InnerJoin;
- }
+ return JoinType.InnerJoin;
}
public ICriteria GetCriteria(string path)
@@ -524,8 +519,8 @@ public string GetSQLAlias(ICriteria criteria)
public string GetEntityName(ICriteria criteria)
{
ICriteriaInfoProvider result;
- if (criteriaInfoMap.TryGetValue(criteria, out result) == false)
- return null;
+ if (criteriaInfoMap.TryGetValue(criteria, out result) == false)
+ return null;
return result.Name;
}
@@ -706,9 +701,9 @@ public string GetPropertyName(string propertyName)
public SqlString GetWithClause(string path, IDictionary<string, IFilter> enabledFilters)
{
- if (withClauseMap.ContainsKey(path))
+ ICriterion crit;
+ if (withClauseMap.TryGetValue(path, out crit))
{
- ICriterion crit = (ICriterion)withClauseMap[path];
return crit == null ? null : crit.ToSqlString(GetCriteria(path), this, enabledFilters);
}
return null;
@@ -735,11 +730,11 @@ private IEnumerable<Parameter> NewQueryParameter(string parameterPrefix, TypedVa
collectedParameterSpecifications.Add(specification);
namedParameters.Add(new NamedParameter(parameterName, parameter.Value, parameter.Type));
return specification.GetIdsForBackTrack(Factory).Select(x =>
- {
- Parameter p = Parameter.Placeholder;
- p.BackTrack = x;
- return p;
- });
+ {
+ Parameter p = Parameter.Placeholder;
+ p.BackTrack = x;
+ return p;
+ });
}
public ICollection<IParameterSpecification> CollectedParameterSpecifications
View
8 src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs
@@ -265,7 +265,7 @@ private void ProcessJoinReturn(NativeSQLQueryJoinReturn fetchReturn)
// Make sure the owner alias is known...
if (!alias2Return.ContainsKey(ownerAlias))
{
- throw new HibernateException("Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]");
+ throw new HibernateException(string.Format("Owner alias [{0}] is unknown for alias [{1}]", ownerAlias, alias));
}
// If this return's alias has not been processed yet, do so b4 further processing of this return
@@ -362,9 +362,9 @@ public IList GenerateCustomReturns(bool queryHadAliases)
string alias = rtn.Alias;
FetchReturn customReturn;
NonScalarReturn ownerCustomReturn = (NonScalarReturn) customReturnsByAlias[rtn.OwnerAlias];
- if (alias2CollectionPersister.ContainsKey(alias))
+ ISqlLoadableCollection persister;
+ if (alias2CollectionPersister.TryGetValue(alias, out persister))
{
- ISqlLoadableCollection persister = alias2CollectionPersister[alias];
bool isEntityElements = persister.ElementType.IsEntityType;
ICollectionAliases collectionAliases;
IEntityAliases elementEntityAliases = null;
@@ -391,7 +391,7 @@ public IList GenerateCustomReturns(bool queryHadAliases)
new CollectionFetchReturn(alias, ownerCustomReturn, rtn.OwnerProperty, collectionAliases, elementEntityAliases,
rtn.LockMode);
}
- else
+ else
{
IEntityAliases entityAliases;
if (queryHadAliases || HasPropertyResultMap(alias))
View
28 src/NHibernate/Loader/JoinWalker.cs
@@ -191,14 +191,16 @@ private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
// add edges
for (int i = 0; i < fields.Count; i++)
{
- if (fields[i].DependsOn != null)
+ var dependentAlias = fields[i];
+ if (dependentAlias.DependsOn != null)
{
- for (int j = 0; j < fields[i].DependsOn.Length; j++)
+ for (int j = 0; j < dependentAlias.DependsOn.Length; j++)
{
- var dependentField = fields[i].DependsOn[j].ToLower();
- if (_indexes.ContainsKey(dependentField))
+ var dependentField = dependentAlias.DependsOn[j].ToLower();
+ int end;
+ if (_indexes.TryGetValue(dependentField, out end))
{
- g.AddEdge(i, _indexes[dependentField]);
+ g.AddEdge(i, end);
}
}
}
@@ -293,8 +295,8 @@ private void WalkCollectionTree(IQueryableCollection persister, string alias, st
}
private void WalkEntityAssociationTree(IAssociationType associationType, IOuterJoinLoadable persister,
- int propertyNumber, string alias, string path, bool nullable, int currentDepth,
- ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
+ int propertyNumber, string alias, string path, bool nullable, int currentDepth,
+ ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
{
string[] aliasedLhsColumns = associationTypeSQLInfo.GetAliasedColumnNames(associationType, 0);
string[] lhsColumns = associationTypeSQLInfo.GetColumnNames(associationType, 0);
@@ -303,7 +305,7 @@ private void WalkCollectionTree(IQueryableCollection persister, string alias, st
string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber));
JoinType joinType = GetJoinType(associationType, persister.GetFetchMode(propertyNumber), subpath, lhsTable,
- lhsColumns, nullable, currentDepth, persister.GetCascadeStyle(propertyNumber));
+ lhsColumns, nullable, currentDepth, persister.GetCascadeStyle(propertyNumber));
AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType);
}
@@ -322,12 +324,12 @@ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias
if (type.IsAssociationType)
{
WalkEntityAssociationTree((IAssociationType) type, persister, i, alias, path,
- persister.IsSubclassPropertyNullable(i), currentDepth, associationTypeSQLInfo);
+ persister.IsSubclassPropertyNullable(i), currentDepth, associationTypeSQLInfo);
}
else if (type.IsComponentType)
{
WalkComponentTree((IAbstractComponentType) type, 0, alias, SubPath(path, persister.GetSubclassPropertyName(i)),
- currentDepth, associationTypeSQLInfo);
+ currentDepth, associationTypeSQLInfo);
}
}
}
@@ -336,7 +338,7 @@ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias
/// For a component, add to a list of associations to be fetched by outerjoin
/// </summary>
protected void WalkComponentTree(IAbstractComponentType componentType, int begin, string alias, string path,
- int currentDepth, ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
+ int currentDepth, ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
{
IType[] types = componentType.Subtypes;
string[] propertyNames = componentType.PropertyNames;
@@ -354,8 +356,8 @@ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias
bool[] propertyNullability = componentType.PropertyNullability;
JoinType joinType = GetJoinType(associationType, componentType.GetFetchMode(i), subpath, lhsTable, lhsColumns,
- propertyNullability == null || propertyNullability[i], currentDepth,
- componentType.GetCascadeStyle(i));
+ propertyNullability == null || propertyNullability[i], currentDepth,
+ componentType.GetCascadeStyle(i));
AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType);
}
View
7 src/NHibernate/NHibernateUtil.cs
@@ -54,11 +54,10 @@ public static IType GuessType(System.Type type)
if(type.IsGenericType && typeof(Nullable<>) == type.GetGenericTypeDefinition())
{
type = type.GetGenericArguments()[0];
- }
- if (clrTypeToNHibernateType.ContainsKey(type))
- {
- return clrTypeToNHibernateType[type];
}
+ IType value;
+ if (clrTypeToNHibernateType.TryGetValue(type, out value))
+ return value;
if (type.IsEnum)
{
return (IType) Activator.CreateInstance(typeof (EnumType<>).MakeGenericType(type));
View
18 src/NHibernate/Util/PropertiesHelper.cs
@@ -50,21 +50,21 @@ public static string GetString(string property, IDictionary<string, string> prop
public static IDictionary<string, string> ToDictionary(string property, string delim, IDictionary<string, string> properties)
{
- IDictionary<string, string> map = new Dictionary<string, string>();
-
- if (properties.ContainsKey(property))
- {
- string propValue = properties[property];
- StringTokenizer tokens = new StringTokenizer(propValue, delim, false);
- IEnumerator<string> en = tokens.GetEnumerator();
+ IDictionary<string, string> map = new Dictionary<string, string>();
+
+ string propValue;
+ if (properties.TryGetValue(property, out propValue))
+ {
+ var tokens = new StringTokenizer(propValue, delim, false);
+ IEnumerator<string> en = tokens.GetEnumerator();
while (en.MoveNext())
{
string key = en.Current;
string value = en.MoveNext() ? en.Current : String.Empty;
map[key] = value;
- }
- }
+ }
+ }
return map;
}

0 comments on commit 3fb22c9

Please sign in to comment.
Something went wrong with that request. Please try again.