Skip to content

Commit

Permalink
Merge pull request #1408 from SimonCropp/remove-duplicate-dictionary-…
Browse files Browse the repository at this point in the history
…lookups-in-ValidationRuleSet.Add

remove duplicate dictionary lookups in ValidationRuleSet.Add
  • Loading branch information
baywet authored Oct 6, 2023
2 parents a184a8f + 88bb6b9 commit 543da26
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,18 @@ public IList<ValidationRule> Rules
/// <param name="rule">The rule.</param>
public void Add(ValidationRule rule)
{
if (!_rules.ContainsKey(rule.ElementType))
if (!_rules.TryGetValue(rule.ElementType, out var item))
{
_rules[rule.ElementType] = new List<ValidationRule>();
_rules[rule.ElementType] = new List<ValidationRule> {rule};
return;
}

if (_rules[rule.ElementType].Contains(rule))
if (item.Contains(rule))
{
throw new OpenApiException(SRResource.Validation_RuleAddTwice);
}

_rules[rule.ElementType].Add(rule);
item.Add(rule);
}

/// <summary>
Expand Down

0 comments on commit 543da26

Please sign in to comment.