Skip to content

Commit 7b7be4a

Browse files
committed
chore; fixes parsing to avoid unnecessary allocations
Signed-off-by: Vincent Biret <[email protected]>
1 parent 512f75c commit 7b7be4a

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal static partial class OpenApiV2Deserializer
104104
}
105105
},
106106
{"security", (o, n, _) => o.SecurityRequirements = n.CreateList(LoadSecurityRequirement, o)},
107-
{"tags", (o, n, _) => o.Tags = new HashSet<OpenApiTag>(n.CreateList(LoadTag, o), OpenApiTagComparer.Instance)},
107+
{"tags", (o, n, _) => { if (n.CreateList(LoadTag, o) is {Count:> 0} tags) {o.Tags = new HashSet<OpenApiTag>(tags, OpenApiTagComparer.Instance); } } },
108108
{"externalDocs", (o, n, _) => o.ExternalDocs = LoadExternalDocs(n, o)}
109109
};
110110

src/Microsoft.OpenApi/Reader/V3/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static partial class OpenApiV3Deserializer
2727
{"servers", (o, n, _) => o.Servers = n.CreateList(LoadServer, o)},
2828
{"paths", (o, n, _) => o.Paths = LoadPaths(n, o)},
2929
{"components", (o, n, _) => o.Components = LoadComponents(n, o)},
30-
{"tags", (o, n, _) => o.Tags = new HashSet<OpenApiTag>(n.CreateList(LoadTag, o), OpenApiTagComparer.Instance) },
30+
{"tags", (o, n, _) => { if (n.CreateList(LoadTag, o) is {Count:> 0} tags) {o.Tags = new HashSet<OpenApiTag>(tags, OpenApiTagComparer.Instance); } } },
3131
{"externalDocs", (o, n, _) => o.ExternalDocs = LoadExternalDocs(n, o)},
3232
{"security", (o, n, _) => o.SecurityRequirements = n.CreateList(LoadSecurityRequirement, o)}
3333
};

src/Microsoft.OpenApi/Reader/V31/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static partial class OpenApiV31Deserializer
2525
{"paths", (o, n, _) => o.Paths = LoadPaths(n, o)},
2626
{"webhooks", (o, n, _) => o.Webhooks = n.CreateMap(LoadPathItem, o)},
2727
{"components", (o, n, _) => o.Components = LoadComponents(n, o)},
28-
{"tags", (o, n, _) => o.Tags = new HashSet<OpenApiTag>(n.CreateList(LoadTag, o), OpenApiTagComparer.Instance) },
28+
{"tags", (o, n, _) => { if (n.CreateList(LoadTag, o) is {Count:> 0} tags) {o.Tags = new HashSet<OpenApiTag>(tags, OpenApiTagComparer.Instance); } } },
2929
{"externalDocs", (o, n, _) => o.ExternalDocs = LoadExternalDocs(n, o)},
3030
{"security", (o, n, _) => o.SecurityRequirements = n.CreateList(LoadSecurityRequirement, o)}
3131
};

0 commit comments

Comments
 (0)