Skip to content

Commit

Permalink
Avoid ServiceBus*Options allocations (#44885)
Browse files Browse the repository at this point in the history
- Avoid allocating empty `ServiceBusClientOptions` and `ServiceBusProcessorOptions` instances when creating instances of `ServiceBusClient` and `ServiceBusProcessor`.
- Remove unused `ServiceBusSenderOptions.Clone()` method.
  • Loading branch information
martincostello authored Jul 9, 2024
1 parent 452d0e1 commit 2c14024
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected ServiceBusClient()
/// Other values will be ignored; to configure the processor, please use the <see cref="ServiceBusClientOptions" />.
/// </remarks>
public ServiceBusClient(string connectionString) :
this(connectionString, new ServiceBusClientOptions())
this(connectionString, null as ServiceBusClientOptions)
{
}

Expand Down Expand Up @@ -192,7 +192,7 @@ public ServiceBusClient(
/// This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
/// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Service Bus namespace.</param>
public ServiceBusClient(string fullyQualifiedNamespace, TokenCredential credential) :
this(fullyQualifiedNamespace, (object)credential, new ServiceBusClientOptions())
this(fullyQualifiedNamespace, (object)credential, null)
{
}

Expand Down Expand Up @@ -562,7 +562,7 @@ public virtual ServiceBusProcessor CreateProcessor(string queueName)
entityPath: queueName,
connection: Connection,
isSessionEntity: false,
options: new ServiceBusProcessorOptions());
options: null);
}

/// <summary>
Expand Down Expand Up @@ -619,7 +619,7 @@ public virtual ServiceBusProcessor CreateProcessor(
entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
connection: Connection,
isSessionEntity: false,
options: new ServiceBusProcessorOptions());
options: null);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,5 @@ public class ServiceBusSenderOptions
///
[EditorBrowsable(EditorBrowsableState.Never)]
public override string ToString() => base.ToString();

/// <summary>
/// Creates a new copy of the current <see cref="ServiceBusReceiverOptions" />, cloning its attributes into a new instance.
/// </summary>
///
/// <returns>A new copy of <see cref="ServiceBusReceiverOptions" />.</returns>
internal ServiceBusSenderOptions Clone() =>
new ServiceBusSenderOptions
{
Identifier = Identifier
};
}
}

0 comments on commit 2c14024

Please sign in to comment.