From 7cd1f2bbd01bc56ad2504fd4799f4a478e0aefdc Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 9 Jul 2024 14:57:40 +0100 Subject: [PATCH] Avoid ServiceBus*Options allocations (#44885) - Avoid allocating empty `ServiceBusClientOptions` and `ServiceBusProcessorOptions` instances when creating instances of `ServiceBusClient` and `ServiceBusProcessor`. - Remove unused `ServiceBusSenderOptions.Clone()` method. --- .../src/Client/ServiceBusClient.cs | 8 ++++---- .../src/Sender/ServiceBusSenderOptions.cs | 11 ----------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs index ce542dad734a1..c77abfe5a787f 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Client/ServiceBusClient.cs @@ -120,7 +120,7 @@ protected ServiceBusClient() /// Other values will be ignored; to configure the processor, please use the . /// public ServiceBusClient(string connectionString) : - this(connectionString, new ServiceBusClientOptions()) + this(connectionString, null as ServiceBusClientOptions) { } @@ -192,7 +192,7 @@ public ServiceBusClient( /// This is likely to be similar to {yournamespace}.servicebus.windows.net. /// The Azure managed identity credential to use for authorization. Access controls may be specified by the Service Bus namespace. public ServiceBusClient(string fullyQualifiedNamespace, TokenCredential credential) : - this(fullyQualifiedNamespace, (object)credential, new ServiceBusClientOptions()) + this(fullyQualifiedNamespace, (object)credential, null) { } @@ -562,7 +562,7 @@ public virtual ServiceBusProcessor CreateProcessor(string queueName) entityPath: queueName, connection: Connection, isSessionEntity: false, - options: new ServiceBusProcessorOptions()); + options: null); } /// @@ -619,7 +619,7 @@ public virtual ServiceBusProcessor CreateProcessor( entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName), connection: Connection, isSessionEntity: false, - options: new ServiceBusProcessorOptions()); + options: null); } /// diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSenderOptions.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSenderOptions.cs index 620c1d38b3a6e..5d515df176115 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSenderOptions.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSenderOptions.cs @@ -44,16 +44,5 @@ public class ServiceBusSenderOptions /// [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() => base.ToString(); - - /// - /// Creates a new copy of the current , cloning its attributes into a new instance. - /// - /// - /// A new copy of . - internal ServiceBusSenderOptions Clone() => - new ServiceBusSenderOptions - { - Identifier = Identifier - }; } }