Skip to content

Commit bc0cebb

Browse files
committed
remove duplicate dictionary lookups in ValidationRuleSet.Add
1 parent 94c811e commit bc0cebb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ public IList<ValidationRule> Rules
123123
/// <param name="rule">The rule.</param>
124124
public void Add(ValidationRule rule)
125125
{
126-
if (!_rules.ContainsKey(rule.ElementType))
126+
if (!_rules.TryGetValue(rule.ElementType, out var item))
127127
{
128-
_rules[rule.ElementType] = new List<ValidationRule>();
128+
_rules[rule.ElementType] = new List<ValidationRule> {rule};
129+
return;
129130
}
130131

131-
if (_rules[rule.ElementType].Contains(rule))
132+
if (item.Contains(rule))
132133
{
133134
throw new OpenApiException(SRResource.Validation_RuleAddTwice);
134135
}

0 commit comments

Comments
 (0)