Skip to content

Commit 6bda890

Browse files
committed
- makes regex static for performance
Signed-off-by: Vincent Biret <[email protected]>
1 parent 9429da4 commit 6bda890

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Text.RegularExpressions;
67
using Microsoft.OpenApi.Models;
@@ -35,21 +36,21 @@ public static class OpenApiPathsRules
3536
}
3637
});
3738

39+
private static readonly Regex regexPath = new Regex("\\{([^/]+)\\}", RegexOptions.Compiled, TimeSpan.FromMilliseconds(100));
3840
/// <summary>
3941
/// A relative path to an individual endpoint. The field name MUST begin with a slash.
4042
/// </summary>
4143
public static ValidationRule<OpenApiPaths> PathMustBeUnique =>
4244
new ValidationRule<OpenApiPaths>(
4345
(context, item) =>
4446
{
45-
const string regexPath = "\\{([^/]+)\\}";
4647
var hashSet = new HashSet<string>();
4748

4849
foreach (var path in item.Keys)
4950
{
5051
context.Enter(path);
5152

52-
var pathSignature = Regex.Replace(path, regexPath, "{}");
53+
var pathSignature = regexPath.Replace(path, "{}");
5354

5455
if (!hashSet.Add(pathSignature))
5556
context.CreateError(nameof(PathMustBeUnique),

0 commit comments

Comments
 (0)