Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/SwaggerProvider.DesignTime/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,23 @@ module XmlDoc =
$"<remarks>{escapeXml description}</remarks>"

let paramParts =
[ for name, desc in paramDescriptions do
if not(String.IsNullOrWhiteSpace desc) then
yield $"<param name=\"{name}\">{escapeXml desc}</param>" ]
|> String.concat ""
let sb = System.Text.StringBuilder()

for name, desc in paramDescriptions do
if not(String.IsNullOrWhiteSpace desc) then
sb.Append("<param name=\"").Append(name).Append("\">").Append(escapeXml desc).Append("</param>")
|> ignore

sb.ToString()

let returnsPart =
match returnDoc with
| Some rd when not(String.IsNullOrWhiteSpace rd) -> $"<returns>{escapeXml rd}</returns>"
| _ -> ""

summaryPart + remarksPart + paramParts + returnsPart
// Use String.Concat with 4 arguments instead of chained + operators to avoid
// two intermediate string allocations (one per + in `a + b + c + d`).
String.Concat(summaryPart, remarksPart, paramParts, returnsPart)

type UniqueNameGenerator(?occupiedNames: string seq) =
let hash = System.Collections.Generic.HashSet<_>()
Expand Down
7 changes: 7 additions & 0 deletions src/SwaggerProvider.Runtime/RuntimeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ module RuntimeHelpers =
| :? DateTime as dt -> dt.ToString("O")
| :? DateTimeOffset as dto -> dto.ToString("O")
| null -> null
// Fast paths for the most common scalar param types:
// these avoid calling GetType() and the four subsequent type checks
// (FullName twice, IsGenericType, IsEnum) that follow in the generic branch.
| :? string as s -> s
| :? int32 as i -> i.ToString()
| :? int64 as i -> i.ToString()
| :? bool as b -> b.ToString()
| _ ->
// Hoist GetType() once; previously tryFormatDateOnly and tryFormatTimeOnly
// each called GetType() internally, resulting in up to 3 GetType() calls for
Expand Down
Loading