Skip to content

Commit

Permalink
Memory optimization from #919: Autofac.Core.Registration.ComponentReg…
Browse files Browse the repository at this point in the history
…istry.
  • Loading branch information
tillig committed Aug 16, 2018
1 parent 7641af7 commit 1ad26e0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Autofac/Core/Registration/ComponentRegistry.cs
Expand Up @@ -55,17 +55,17 @@ public class ComponentRegistry : Disposable, IComponentRegistry
/// <summary>
/// External registration sources.
/// </summary>
private readonly IList<IRegistrationSource> _dynamicRegistrationSources = new List<IRegistrationSource>();
private readonly List<IRegistrationSource> _dynamicRegistrationSources = new List<IRegistrationSource>();

/// <summary>
/// All registrations.
/// </summary>
private readonly ICollection<IComponentRegistration> _registrations = new List<IComponentRegistration>();
private readonly List<IComponentRegistration> _registrations = new List<IComponentRegistration>();

/// <summary>
/// Keeps track of the status of registered services.
/// </summary>
private readonly IDictionary<Service, ServiceRegistrationInfo> _serviceInfo = new Dictionary<Service, ServiceRegistrationInfo>();
private readonly Dictionary<Service, ServiceRegistrationInfo> _serviceInfo = new Dictionary<Service, ServiceRegistrationInfo>();

private readonly ConcurrentDictionary<IComponentRegistration, IEnumerable<IComponentRegistration>> _decorators
= new ConcurrentDictionary<IComponentRegistration, IEnumerable<IComponentRegistration>>();
Expand Down Expand Up @@ -168,12 +168,16 @@ public void Register(IComponentRegistration registration, bool preserveDefaults)

private void UpdateInitialisedAdapters(IComponentRegistration registration)
{
var adapterServices = _serviceInfo
.Where(si => si.Value.ShouldRecalculateAdaptersOn(registration))
.Select(si => si.Key)
.ToArray();
var adapterServices = new List<Service>();
foreach (var serviceInfo in _serviceInfo)
{
if (serviceInfo.Value.ShouldRecalculateAdaptersOn(registration))
{
adapterServices.Add(serviceInfo.Key);
}
}

if (adapterServices.Length == 0)
if (adapterServices.Count == 0)
return;

Debug.WriteLine(
Expand Down

0 comments on commit 1ad26e0

Please sign in to comment.