From bcbb9a02a7287abf59ad4e8751f0bc5bfd4d641c Mon Sep 17 00:00:00 2001 From: "denys.kozhevnikov" Date: Wed, 10 May 2023 16:19:23 +0100 Subject: [PATCH] Predefine list size for connectors --- .../Consumers/Configuration/ConsumerConnector.cs | 7 +++---- .../Consumers/Configuration/InstanceConnector.cs | 4 ++-- .../Configuration/StateMachineConnector.cs | 2 +- .../Configuration/StateMachineSagaConfigurator.cs | 3 +-- src/MassTransit/Sagas/Configuration/SagaConnector.cs | 2 +- src/MassTransit/Testing/MultiTestConsumer.cs | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/MassTransit/Consumers/Configuration/ConsumerConnector.cs b/src/MassTransit/Consumers/Configuration/ConsumerConnector.cs index 46fe594b2c7..08b68ee23d3 100644 --- a/src/MassTransit/Consumers/Configuration/ConsumerConnector.cs +++ b/src/MassTransit/Consumers/Configuration/ConsumerConnector.cs @@ -10,15 +10,14 @@ public class ConsumerConnector : IConsumerConnector where T : class { - readonly IEnumerable> _connectors; + readonly IList> _connectors; public ConsumerConnector() { if (MessageTypeCache.HasSagaInterfaces) throw new ConfigurationException("A saga cannot be registered as a consumer"); - _connectors = Consumes() - .ToList(); + _connectors = Consumes().ToList(); } public IEnumerable Connectors => _connectors; @@ -26,7 +25,7 @@ public ConsumerConnector() ConnectHandle IConsumerConnector.ConnectConsumer(IConsumePipeConnector consumePipe, IConsumerFactory consumerFactory, IConsumerSpecification specification) { - var handles = new List(); + var handles = new List(_connectors.Count); try { foreach (IConsumerMessageConnector connector in _connectors.Cast>()) diff --git a/src/MassTransit/Consumers/Configuration/InstanceConnector.cs b/src/MassTransit/Consumers/Configuration/InstanceConnector.cs index 985b99ec52c..b1079be4405 100644 --- a/src/MassTransit/Consumers/Configuration/InstanceConnector.cs +++ b/src/MassTransit/Consumers/Configuration/InstanceConnector.cs @@ -10,7 +10,7 @@ public class InstanceConnector : IInstanceConnector where TConsumer : class { - readonly IEnumerable> _connectors; + readonly IList> _connectors; public InstanceConnector() { @@ -24,7 +24,7 @@ public InstanceConnector() public ConnectHandle ConnectInstance(IConsumePipeConnector pipeConnector, T instance, IConsumerSpecification specification) where T : class { - var handles = new List(); + var handles = new List(_connectors.Count); try { foreach (IInstanceMessageConnector connector in _connectors.Cast>()) diff --git a/src/MassTransit/SagaStateMachine/Configuration/StateMachineConnector.cs b/src/MassTransit/SagaStateMachine/Configuration/StateMachineConnector.cs index 196468e329a..796c2c6f2b6 100644 --- a/src/MassTransit/SagaStateMachine/Configuration/StateMachineConnector.cs +++ b/src/MassTransit/SagaStateMachine/Configuration/StateMachineConnector.cs @@ -43,7 +43,7 @@ public ISagaSpecification CreateSagaSpecification() public ConnectHandle ConnectSaga(IConsumePipeConnector consumePipe, ISagaRepository sagaRepository, ISagaSpecification specification) where T : class, ISaga { - var handles = new List(); + var handles = new List(_connectors.Count); try { foreach (ISagaMessageConnector connector in _connectors.Cast>()) diff --git a/src/MassTransit/SagaStateMachine/Configuration/StateMachineSagaConfigurator.cs b/src/MassTransit/SagaStateMachine/Configuration/StateMachineSagaConfigurator.cs index f099ed0c15f..bf853f5550d 100644 --- a/src/MassTransit/SagaStateMachine/Configuration/StateMachineSagaConfigurator.cs +++ b/src/MassTransit/SagaStateMachine/Configuration/StateMachineSagaConfigurator.cs @@ -28,8 +28,7 @@ public StateMachineSagaConfigurator(SagaStateMachine stateMachine, IS public IEnumerable Validate() { - foreach (var result in _specification.Validate()) - yield return result; + return _specification.Validate(); } public void Configure(IReceiveEndpointBuilder builder) diff --git a/src/MassTransit/Sagas/Configuration/SagaConnector.cs b/src/MassTransit/Sagas/Configuration/SagaConnector.cs index 35e17819d2e..9e982091431 100644 --- a/src/MassTransit/Sagas/Configuration/SagaConnector.cs +++ b/src/MassTransit/Sagas/Configuration/SagaConnector.cs @@ -43,7 +43,7 @@ ISagaSpecification ISagaConnector.CreateSagaSpecification() ConnectHandle ISagaConnector.ConnectSaga(IConsumePipeConnector consumePipe, ISagaRepository repository, ISagaSpecification specification) { - var handles = new List(); + var handles = new List(_connectors.Count); try { foreach (ISagaMessageConnector connector in _connectors.Cast>()) diff --git a/src/MassTransit/Testing/MultiTestConsumer.cs b/src/MassTransit/Testing/MultiTestConsumer.cs index f3de672b8e5..38befdd732d 100644 --- a/src/MassTransit/Testing/MultiTestConsumer.cs +++ b/src/MassTransit/Testing/MultiTestConsumer.cs @@ -47,7 +47,7 @@ public ReceivedMessageList Fault() public ConnectHandle Connect(IConsumePipeConnector bus) { - var handles = new List(); + var handles = new List(_configures.Count); try { foreach (var configure in _configures)