forked from domaindrivendev/Swashbuckle.AspNetCore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve IncludeXmlComments performance (2) (domaindrivendev#3044)
* Improve IncludeXmlComments performance Co-authored-by: steven.darby <[email protected]> * Add braces Co-authored-by: Martin Costello <[email protected]> * Use ??= operator Co-authored-by: Martin Costello <[email protected]> * use file scoped namespaces * use constant for empty XML namespace and add SelectChild/GetAttribute extensions for consistency. * Rename GetMemberDictionary to CreateMemberDictionary * use concrete Dictionary type * use file-scoped namespace * revert file-scoped namespace didn't mean to touch this file. * use OfType instead of Cast --------- Co-authored-by: steven.darby <[email protected]> Co-authored-by: Martin Costello <[email protected]>
- Loading branch information
1 parent
d358e7b
commit 90f302d
Showing
9 changed files
with
206 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XPathNavigatorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Linq; | ||
using System.Xml.XPath; | ||
|
||
namespace Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
internal static class XPathNavigatorExtensions | ||
{ | ||
private const string EmptyNamespace = ""; | ||
|
||
internal static XPathNodeIterator SelectChildren(this XPathNavigator navigator, string name) | ||
{ | ||
return navigator.SelectChildren(name, EmptyNamespace); | ||
} | ||
|
||
internal static string GetAttribute(this XPathNavigator navigator, string name) | ||
{ | ||
return navigator.GetAttribute(name, EmptyNamespace); | ||
} | ||
|
||
internal static XPathNavigator SelectFirstChild(this XPathNavigator navigator, string name) | ||
{ | ||
return navigator.SelectChildren(name, EmptyNamespace) | ||
?.OfType<XPathNavigator>() | ||
.FirstOrDefault(); | ||
} | ||
|
||
internal static XPathNavigator SelectFirstChildWithAttribute(this XPathNavigator navigator, string childName, string attributeName, string attributeValue) | ||
{ | ||
return navigator.SelectChildren(childName, EmptyNamespace) | ||
?.OfType<XPathNavigator>() | ||
.FirstOrDefault(n => n.GetAttribute(attributeName, EmptyNamespace) == attributeValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsDocumentHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml.XPath; | ||
|
||
namespace Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
internal static class XmlCommentsDocumentHelper | ||
{ | ||
internal static Dictionary<string, XPathNavigator> CreateMemberDictionary(XPathDocument xmlDoc) | ||
{ | ||
var members = xmlDoc.CreateNavigator() | ||
.SelectFirstChild("doc") | ||
?.SelectFirstChild("members") | ||
?.SelectChildren("member") | ||
?.OfType<XPathNavigator>(); | ||
|
||
if (members == null) | ||
{ | ||
return new Dictionary<string, XPathNavigator>(); | ||
} | ||
|
||
return members.ToDictionary(memberNode => memberNode.GetAttribute("name")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.