Skip to content

Commit 0546f1a

Browse files
bollhalsmichaelklishin
authored andcommitted
use cached empty BasicProperties when null
1 parent 2f44cc0 commit 0546f1a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

projects/RabbitMQ.Client/client/impl/BasicPublishBatch.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ public void Add(string exchange, string routingKey, bool mandatory, IBasicProper
6363

6464
public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory<byte> body)
6565
{
66-
IBasicProperties bp = basicProperties ?? _model.CreateBasicProperties();
6766
var method = new BasicPublish
6867
{
6968
_exchange = exchange,
7069
_routingKey = routingKey,
7170
_mandatory = mandatory
7271
};
7372

74-
_commands.Add(new Command(method, (ContentHeaderBase)bp, body, false));
73+
_commands.Add(new Command(method, (ContentHeaderBase)(basicProperties ?? _model._emptyBasicProperties), body, false));
7574
}
7675

7776
public void Publish()

projects/RabbitMQ.Client/client/impl/ModelBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ abstract class ModelBase : IFullModel, IRecoverable
5858
///<summary>Only used to kick-start a connection open
5959
///sequence. See <see cref="Connection.Open"/> </summary>
6060
public BlockingCell<ConnectionStartDetails> m_connectionStartCell = null;
61+
internal readonly IBasicProperties _emptyBasicProperties;
6162

6263
private readonly Dictionary<string, IBasicConsumer> _consumers = new Dictionary<string, IBasicConsumer>();
6364

@@ -72,7 +73,6 @@ abstract class ModelBase : IFullModel, IRecoverable
7273
private readonly object _confirmLock = new object();
7374
private readonly LinkedList<ulong> _pendingDeliveryTags = new LinkedList<ulong>();
7475
private readonly CountdownEvent _deliveryTagsCountdown = new CountdownEvent(0);
75-
7676
private EventHandler<ShutdownEventArgs> _modelShutdown;
7777

7878
private bool _onlyAcksReceived = true;
@@ -93,6 +93,7 @@ public ModelBase(ISession session, ConsumerWorkService workService)
9393
ConsumerDispatcher = new ConcurrentConsumerDispatcher(this, workService);
9494
}
9595

96+
_emptyBasicProperties = CreateBasicProperties();
9697
Initialise(session);
9798
}
9899

@@ -1111,7 +1112,7 @@ public void BasicPublish(string exchange,
11111112

11121113
if (basicProperties == null)
11131114
{
1114-
basicProperties = CreateBasicProperties();
1115+
basicProperties = _emptyBasicProperties;
11151116
}
11161117

11171118
if (NextPublishSeqNo > 0)

0 commit comments

Comments
 (0)