Skip to content

Commit

Permalink
Predefine list size for connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
NooNameR authored and phatboyg committed May 22, 2023
1 parent 9de5979 commit bcbb9a0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/MassTransit/Consumers/Configuration/ConsumerConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ public class ConsumerConnector<T> :
IConsumerConnector
where T : class
{
readonly IEnumerable<IConsumerMessageConnector<T>> _connectors;
readonly IList<IConsumerMessageConnector<T>> _connectors;

public ConsumerConnector()
{
if (MessageTypeCache<T>.HasSagaInterfaces)
throw new ConfigurationException("A saga cannot be registered as a consumer");

_connectors = Consumes()
.ToList();
_connectors = Consumes().ToList();
}

public IEnumerable<IConsumerMessageConnector> Connectors => _connectors;

ConnectHandle IConsumerConnector.ConnectConsumer<TConsumer>(IConsumePipeConnector consumePipe, IConsumerFactory<TConsumer> consumerFactory,
IConsumerSpecification<TConsumer> specification)
{
var handles = new List<ConnectHandle>();
var handles = new List<ConnectHandle>(_connectors.Count);
try
{
foreach (IConsumerMessageConnector<TConsumer> connector in _connectors.Cast<IConsumerMessageConnector<TConsumer>>())
Expand Down
4 changes: 2 additions & 2 deletions src/MassTransit/Consumers/Configuration/InstanceConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class InstanceConnector<TConsumer> :
IInstanceConnector
where TConsumer : class
{
readonly IEnumerable<IInstanceMessageConnector<TConsumer>> _connectors;
readonly IList<IInstanceMessageConnector<TConsumer>> _connectors;

public InstanceConnector()
{
Expand All @@ -24,7 +24,7 @@ public InstanceConnector()
public ConnectHandle ConnectInstance<T>(IConsumePipeConnector pipeConnector, T instance, IConsumerSpecification<T> specification)
where T : class
{
var handles = new List<ConnectHandle>();
var handles = new List<ConnectHandle>(_connectors.Count);
try
{
foreach (IInstanceMessageConnector<T> connector in _connectors.Cast<IInstanceMessageConnector<T>>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ISagaSpecification<T> CreateSagaSpecification<T>()
public ConnectHandle ConnectSaga<T>(IConsumePipeConnector consumePipe, ISagaRepository<T> sagaRepository, ISagaSpecification<T> specification)
where T : class, ISaga
{
var handles = new List<ConnectHandle>();
var handles = new List<ConnectHandle>(_connectors.Count);
try
{
foreach (ISagaMessageConnector<T> connector in _connectors.Cast<ISagaMessageConnector<T>>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public StateMachineSagaConfigurator(SagaStateMachine<TInstance> stateMachine, IS

public IEnumerable<ValidationResult> Validate()
{
foreach (var result in _specification.Validate())
yield return result;
return _specification.Validate();
}

public void Configure(IReceiveEndpointBuilder builder)
Expand Down
2 changes: 1 addition & 1 deletion src/MassTransit/Sagas/Configuration/SagaConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ISagaSpecification<T> ISagaConnector.CreateSagaSpecification<T>()

ConnectHandle ISagaConnector.ConnectSaga<T>(IConsumePipeConnector consumePipe, ISagaRepository<T> repository, ISagaSpecification<T> specification)
{
var handles = new List<ConnectHandle>();
var handles = new List<ConnectHandle>(_connectors.Count);
try
{
foreach (ISagaMessageConnector<T> connector in _connectors.Cast<ISagaMessageConnector<T>>())
Expand Down
2 changes: 1 addition & 1 deletion src/MassTransit/Testing/MultiTestConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ReceivedMessageList<T> Fault<T>()

public ConnectHandle Connect(IConsumePipeConnector bus)
{
var handles = new List<ConnectHandle>();
var handles = new List<ConnectHandle>(_configures.Count);
try
{
foreach (var configure in _configures)
Expand Down

0 comments on commit bcbb9a0

Please sign in to comment.