Skip to content

Commit

Permalink
Remove defensive Dictionary copies
Browse files Browse the repository at this point in the history
-NavigationExpandingExpressionVisitor: ToList() is not needed anymore, as we remove from IncludeTreeNode which inherites from Dictionary
- TableSharingConcurrencyTokenConvention: no need for deferring removal from collection and ToList() as entityTypeDictionary is Dictionary

Fixes #18598

Authored-by: Michał Czerwiński <mcr@spyro-soft.com>
  • Loading branch information
michalczerwinski authored May 4, 2021
1 parent 67a5d16 commit 470e45c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,31 +234,24 @@ public static bool IsConcurrencyTokenMissing(

private static void RemoveDerivedEntityTypes<T>(Dictionary<IConventionEntityType, T> entityTypeDictionary)
{
var toRemove = new HashSet<KeyValuePair<IConventionEntityType, T>>();
var entityTypesWithDerivedTypes =
entityTypeDictionary.Where(e => e.Key.GetDirectlyDerivedTypes().Any()).ToList();
entityTypeDictionary.Where(e => e.Key.GetDirectlyDerivedTypes().Any());
foreach (var entityType in entityTypeDictionary.Where(e => e.Key.BaseType != null))
{
foreach (var otherEntityType in entityTypesWithDerivedTypes)
{
if (toRemove.Contains(otherEntityType)
|| otherEntityType.Equals(entityType))
if (otherEntityType.Equals(entityType))
{
continue;
}

if (otherEntityType.Key.IsAssignableFrom(entityType.Key))
{
toRemove.Add(entityType);
entityTypeDictionary.Remove(entityType.Key);
break;
}
}
}

foreach (var entityType in toRemove)
{
entityTypeDictionary.Remove(entityType.Key);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ private NavigationExpansionExpression ProcessCastOfType(
var siblingNavigations = newEntityReference.IncludePaths.Keys
.Where(
n => !castEntityType.IsAssignableFrom(n.DeclaringEntityType)
&& !n.DeclaringEntityType.IsAssignableFrom(castEntityType)).ToList();
&& !n.DeclaringEntityType.IsAssignableFrom(castEntityType));

foreach (var navigation in siblingNavigations)
{
Expand Down

0 comments on commit 470e45c

Please sign in to comment.