Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce some linq allocation #2819

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public static bool IsDictionaryValueNonNullable(this MemberInfo memberInfo)

private static object GetNullableAttribute(this MemberInfo memberInfo)
{
var nullableAttribute = memberInfo.GetCustomAttributes()
.Where(attr => string.Equals(attr.GetType().FullName, NullableAttributeFullTypeName))
.FirstOrDefault();
var nullableAttribute = memberInfo
.GetCustomAttributes()
.FirstOrDefault(attr => string.Equals(attr.GetType().FullName, NullableAttributeFullTypeName));

return nullableAttribute;
}
Expand All @@ -103,8 +103,7 @@ private static bool GetNullableFallbackValue(this MemberInfo memberInfo)
var attributes = (IEnumerable<object>)declaringType.GetCustomAttributes(false);

var nullableContext = attributes
.Where(attr => string.Equals(attr.GetType().FullName, NullableContextAttributeFullTypeName))
.FirstOrDefault();
.FirstOrDefault(attr => string.Equals(attr.GetType().FullName, NullableContextAttributeFullTypeName));

if (nullableContext != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ public OpenApiDocument GetSwagger(string documentName, string host = null, strin

var applicableApiDescriptions = _apiDescriptionsProvider.ApiDescriptionGroups.Items
.SelectMany(group => group.Items)
.Where(apiDesc => !(_options.IgnoreObsoleteActions && apiDesc.CustomAttributes().OfType<ObsoleteAttribute>().Any()))
.Where(apiDesc => !apiDesc.CustomAttributes().OfType<SwaggerIgnoreAttribute>().Any())
.Where(apiDesc => _options.DocInclusionPredicate(documentName, apiDesc));
.Where(apiDesc =>
{
var attributes = apiDesc.CustomAttributes().ToList();
return !(_options.IgnoreObsoleteActions && attributes.OfType<ObsoleteAttribute>().Any()) &&
!attributes.OfType<SwaggerIgnoreAttribute>().Any() &&
_options.DocInclusionPredicate(documentName, apiDesc);
});

var schemaRepository = new SchemaRepository(documentName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public static ApiDescription Create(
// If the provided action has a matching parameter - use it to assign ParameterDescriptor & ModelMetadata
parameter.ParameterDescriptor = actionDescriptor.Parameters
.OfType<ParameterDescriptor>()
.Where(parameterDescriptor => parameterDescriptor.Name == parameter.Name)
.FirstOrDefault();
.FirstOrDefault(parameterDescriptor => parameterDescriptor.Name == parameter.Name);

var parameterDescriptorWithParameterInfo = parameter.ParameterDescriptor as
#if NETCOREAPP2_2_OR_GREATER
Expand Down