Skip to content

Commit c44b851

Browse files
authored
[Event Hubs] Avoid Possible Allocation (#22632)
The focus of these changes is to alter the approach used for copying an AMQP message section dictionary to avoid a possible allocation of the `Keys` collection of the source dictionary when no items are present.
1 parent 2e9f076 commit c44b851

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sdk/eventhub/Azure.Messaging.EventHubs/src/Amqp/AmqpAnnotatedMessageExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,12 @@ private static void CopyPropertiesSection(AmqpMessageProperties source,
399399
private static void CopyDictionary<TKey, TValue>(IDictionary<TKey, TValue> source,
400400
IDictionary<TKey, TValue> destination)
401401
{
402-
foreach (var key in source.Keys)
402+
if (source.Count > 0)
403403
{
404-
destination[key] = source[key];
404+
foreach (var pair in source)
405+
{
406+
destination[pair.Key] = pair.Value;
407+
}
405408
}
406409
}
407410
}

0 commit comments

Comments
 (0)