Skip to content

Commit

Permalink
use some compound assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 13, 2023
1 parent 19adf9f commit 6b8cfc0
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Polly/Caching/AsyncCacheSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITt
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));

onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };

return new AsyncCachePolicy(cacheProvider, ttlStrategy, cacheKeyStrategy.GetCacheKey, emptyDelegate, emptyDelegate, emptyDelegate, onCacheError, onCacheError);
Expand Down Expand Up @@ -110,7 +110,7 @@ public static AsyncCachePolicy CacheAsync(IAsyncCacheProvider cacheProvider, ITt
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));

onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };

return new AsyncCachePolicy(cacheProvider, ttlStrategy, cacheKeyStrategy, emptyDelegate, emptyDelegate, emptyDelegate, onCacheError, onCacheError);
Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Caching/AsyncCacheTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand All @@ -440,7 +440,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -479,7 +479,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand All @@ -502,7 +502,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Caching/CacheSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy t
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));

onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };

return Cache(cacheProvider, ttlStrategy, cacheKeyStrategy.GetCacheKey, emptyDelegate, emptyDelegate, emptyDelegate, onCacheError, onCacheError);
Expand Down Expand Up @@ -110,7 +110,7 @@ public static CachePolicy Cache(ISyncCacheProvider cacheProvider, ITtlStrategy t
if (ttlStrategy == null) throw new ArgumentNullException(nameof(ttlStrategy));
if (cacheKeyStrategy == null) throw new ArgumentNullException(nameof(cacheKeyStrategy));

onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };
Action<Context, string> emptyDelegate = (_, _) => { };

return Cache(cacheProvider, ttlStrategy, cacheKeyStrategy, emptyDelegate, emptyDelegate, emptyDelegate, onCacheError, onCacheError);
Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Caching/CacheTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand All @@ -441,7 +441,7 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down Expand Up @@ -481,7 +481,7 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand All @@ -505,7 +505,7 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });
onCacheError ??= (_, _, _) => { };

Action<Context, string> emptyDelegate = (_, _) => { };

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/AdvancedCircuitController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void OnActionFailure(DelegateResult<TResult> outcome, Context co
var healthCount = _metrics.GetHealthCount_NeedsLock();

int throughput = healthCount.Total;
if (throughput >= _minimumThroughput && ((double)healthCount.Failures) / throughput >= _failureThreshold)
if (throughput >= _minimumThroughput && (double)healthCount.Failures / throughput >= _failureThreshold)
{
Break_NeedsLock(context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/RollingHealthMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void ActualiseCurrentMetric_NeedsLock()
_windows.Enqueue(_currentWindow);
}

while (_windows.Count > 0 && (now - _windows.Peek().StartedAt >= _samplingDuration))
while (_windows.Count > 0 && now - _windows.Peek().StartedAt >= _samplingDuration)
_windows.Dequeue();
}
}
2 changes: 1 addition & 1 deletion src/Polly/ExceptionPredicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ExceptionPredicates

internal void Add(ExceptionPredicate predicate)
{
_predicates = _predicates ?? new List<ExceptionPredicate>(); // The ?? pattern here is sufficient; only a deliberately contrived example would lead to the same PolicyBuilder instance being used in a multi-threaded way to define policies simultaneously on multiple threads.
_predicates ??= new List<ExceptionPredicate>(); // The ?? pattern here is sufficient; only a deliberately contrived example would lead to the same PolicyBuilder instance being used in a multi-threaded way to define policies simultaneously on multiple threads.

_predicates.Add(predicate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Polly/PolicyBuilder.OrSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PolicyBuilder Or<TException>(Func<TException, bool> exceptionPredicate) w
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder OrInner<TException>() where TException : Exception
{
ExceptionPredicates.Add((HandleInner(ex => ex is TException)));
ExceptionPredicates.Add(HandleInner(ex => ex is TException));
return this;
}

Expand Down Expand Up @@ -160,7 +160,7 @@ public PolicyBuilder<TResult> Or<TException>(Func<TException, bool> exceptionPre
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder<TResult> OrInner<TException>() where TException : Exception
{
ExceptionPredicates.Add((PolicyBuilder.HandleInner(ex => ex is TException)));
ExceptionPredicates.Add(PolicyBuilder.HandleInner(ex => ex is TException));
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public LockFreeTokenBucketRateLimiter(TimeSpan onePer, long bucketCapacity)
// Passing addNextTokenAtTicks merits one token
1 +
// And any whole token tick intervals further each merit another.
(-ticksTillAddNextToken / addTokenTickInterval);
-ticksTillAddNextToken / addTokenTickInterval;

// We mustn't exceed bucket capacity though.
long tokensToAdd = Math.Min(bucketCapacity, tokensMissedAdding);

// Work out when tokens would next be due to be added, if we add these tokens.
long newAddNextTokenAtTicks = currentAddNextTokenAtTicks + (tokensToAdd * addTokenTickInterval);
long newAddNextTokenAtTicks = currentAddNextTokenAtTicks + tokensToAdd * addTokenTickInterval;
// But if we were way overdue refilling the bucket (there was inactivity for a while), that value would be out-of-date: the next time we add tokens must be at least addTokenTickInterval from now.
newAddNextTokenAtTicks = Math.Max(newAddNextTokenAtTicks, now + addTokenTickInterval);

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/ResultPredicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ResultPredicates<TResult>

internal void Add(ResultPredicate<TResult> predicate)
{
_predicates = _predicates ?? new List<ResultPredicate<TResult>>(); // The ?? pattern here is sufficient; only a deliberately contrived example would lead to the same PolicyBuilder instance being used in a multi-threaded way to define policies simultaneously on multiple threads.
_predicates ??= new List<ResultPredicate<TResult>>(); // The ?? pattern here is sufficient; only a deliberately contrived example would lead to the same PolicyBuilder instance being used in a multi-threaded way to define policies simultaneously on multiple threads.

_predicates.Add(predicate);
}
Expand Down

0 comments on commit 6b8cfc0

Please sign in to comment.