Skip to content

Commit 7a6be84

Browse files
committed
perf: reduce allocations translating paths
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 6dc21b3 commit 7a6be84

File tree

2 files changed

+175
-171
lines changed

2 files changed

+175
-171
lines changed

src/Microsoft.OpenApi/Services/IOpenApiPathRepresentationPolicy.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33

44
namespace Microsoft.OpenApi;
55
/// <summary>
6-
/// Defines a policy for matching and transforming OpenAPI JSON Pointer paths
6+
/// Defines a policy for matching and transforming OpenAPI JSON Pointer path segments
77
/// between specification versions.
88
/// </summary>
99
internal interface IOpenApiPathRepresentationPolicy
1010
{
1111
/// <summary>
12-
/// Determines whether this policy can handle the given path.
12+
/// Attempts to transform the given path segments to the equivalent in the target version.
1313
/// </summary>
14-
/// <param name="path">The JSON Pointer path to evaluate.</param>
15-
/// <returns><c>true</c> if this policy applies to the given path; otherwise, <c>false</c>.</returns>
16-
bool IsMatch(string path);
17-
18-
/// <summary>
19-
/// Transforms the given path to its equivalent in the target specification version.
20-
/// </summary>
21-
/// <param name="path">The JSON Pointer path to transform.</param>
22-
/// <returns>The transformed path, or <c>null</c> if the path has no equivalent in the target version.</returns>
23-
string? GetVersionedPath(string path);
14+
/// <param name="segments">The pre-parsed path segments (without the <c>#/</c> prefix).</param>
15+
/// <param name="result">
16+
/// When this method returns <c>true</c>, contains the transformed path or <c>null</c>
17+
/// if the path has no equivalent in the target version.
18+
/// </param>
19+
/// <returns><c>true</c> if this policy handled the path; <c>false</c> to try the next policy.</returns>
20+
bool TryGetVersionedPath(string[] segments, out string? result);
2421
}

0 commit comments

Comments
 (0)