From 59b29d2d23ef25bf025bb618f33619341c99cefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 29 Oct 2017 13:25:26 +0100 Subject: [PATCH] Optimization: update SetPostLogoutRedirectUrisAsync() and SetRedirectUrisAsync() to avoid running checks for default or empty arrays --- .../Stores/IOpenIddictApplicationStore.cs | 4 ++-- .../Stores/OpenIddictApplicationStore.cs | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs index b228dd2b..e4380153 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs @@ -276,7 +276,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// Task SetPostLogoutRedirectUrisAsync([NotNull] TApplication application, - [NotNull] ImmutableArray addresses, CancellationToken cancellationToken); + ImmutableArray addresses, CancellationToken cancellationToken); /// /// Sets the callback addresses associated with an application. @@ -288,7 +288,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// Task SetRedirectUrisAsync([NotNull] TApplication application, - [NotNull] ImmutableArray addresses, CancellationToken cancellationToken); + ImmutableArray addresses, CancellationToken cancellationToken); /// /// Updates an existing application. diff --git a/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs index d2f24866..2b9564ff 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs @@ -555,16 +555,18 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual Task SetPostLogoutRedirectUrisAsync([NotNull] TApplication application, - [NotNull] ImmutableArray addresses, CancellationToken cancellationToken) + ImmutableArray addresses, CancellationToken cancellationToken) { if (application == null) { - throw new ArgumentException(nameof(application)); + throw new ArgumentNullException(nameof(application)); } - if (addresses == null) + if (addresses.IsDefaultOrEmpty) { - throw new ArgumentException(nameof(addresses)); + application.PostLogoutRedirectUris = null; + + return Task.CompletedTask; } if (addresses.Any(address => string.IsNullOrEmpty(address))) @@ -592,16 +594,18 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual Task SetRedirectUrisAsync([NotNull] TApplication application, - [NotNull] ImmutableArray addresses, CancellationToken cancellationToken) + ImmutableArray addresses, CancellationToken cancellationToken) { if (application == null) { - throw new ArgumentException(nameof(application)); + throw new ArgumentNullException(nameof(application)); } - if (addresses == null) + if (addresses.IsDefaultOrEmpty) { - throw new ArgumentException(nameof(addresses)); + application.RedirectUris = null; + + return Task.CompletedTask; } if (addresses.Any(address => string.IsNullOrEmpty(address)))