Skip to content

Commit

Permalink
Replace ConcurrentDictionary with HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzajac committed Dec 4, 2023
1 parent 1af9618 commit 3384ab4
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Objectivity.AutoFixture.XUnit2.Core.SpecimenBuilders
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

Expand All @@ -22,20 +22,19 @@ public object Create(object request, ISpecimenContext context)

if (request.NotNull(nameof(request)) is ExceptValuesRequest exceptValuesRequest)
{
var duplicateLimiter = new ConcurrentDictionary<object, bool>();
var duplicateLimiter = new HashSet<object>();
object result;

do
{
result = context.Resolve(exceptValuesRequest.OperandType);
var hasDuplicate = duplicateLimiter.AddOrUpdate(
result,
(_) => false,
(_, __) => true);
var hasDuplicate = duplicateLimiter.Contains(result);
if (hasDuplicate)
{
throw new ObjectCreationException("The value could not be created. Probably all possible values were excluded.");
}

duplicateLimiter.Add(result);
}
while (exceptValuesRequest.Values.Contains(result));

Expand Down

0 comments on commit 3384ab4

Please sign in to comment.