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

Remove factory from value generator cache key #25925

Merged
merged 1 commit into from
Sep 8, 2021
Merged
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
7 changes: 2 additions & 5 deletions src/EFCore/ValueGeneration/ValueGeneratorCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,16 @@ public ValueGeneratorCache(ValueGeneratorCacheDependencies dependencies)

private readonly struct CacheKey : IEquatable<CacheKey>
{
public CacheKey(IProperty property, IEntityType entityType, Func<IProperty, IEntityType, ValueGenerator> factory)
public CacheKey(IProperty property, IEntityType entityType)
{
Property = property;
EntityType = entityType;
Factory = factory;
}

public IProperty Property { get; }

public IEntityType EntityType { get; }

public Func<IProperty, IEntityType, ValueGenerator> Factory { get; }

public bool Equals(CacheKey other)
=> Property.Equals(other.Property) && EntityType.Equals(other.EntityType);

Expand Down Expand Up @@ -87,7 +84,7 @@ public virtual ValueGenerator GetOrAdd(
Check.NotNull(property, nameof(property));
Check.NotNull(factory, nameof(factory));

return _cache.GetOrAdd(new CacheKey(property, entityType, factory), ck => ck.Factory(ck.Property, ck.EntityType));
return _cache.GetOrAdd(new CacheKey(property, entityType), static (ck, f) => f(ck.Property, ck.EntityType), factory);
}
}
}