Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Apr 3, 2021
1 parent 52daca7 commit 8877dbc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ internal static class ControllerBinderDelegateProvider
return null;
}

var parameters = actionDescriptor.Parameters as List<ParameterDescriptor> ?? actionDescriptor.Parameters.ToList();
var properties = actionDescriptor.BoundProperties as List<ParameterDescriptor> ?? actionDescriptor.BoundProperties.ToList();
var parameters = actionDescriptor.Parameters switch
{
List<ParameterDescriptor> list => list.ToArray(),
_ => actionDescriptor.Parameters.ToArray()
};

var properties = actionDescriptor.BoundProperties switch
{
List<ParameterDescriptor> list => list.ToArray(),
_ => actionDescriptor.BoundProperties.ToArray()
};

return Bind;

Expand All @@ -72,8 +81,7 @@ async Task Bind(ControllerContext controllerContext, object controller, Dictiona

Debug.Assert(valueProvider is not null);

var parameterCount = parameters.Count;
for (var i = 0; i < parameterCount; i++)
for (var i = 0; i < parameters.Length; i++)
{
var parameter = parameters[i];
var bindingInfo = parameterBindingInfo![i];
Expand All @@ -99,8 +107,7 @@ async Task Bind(ControllerContext controllerContext, object controller, Dictiona
}
}

var propertyCount = properties.Count;
for (var i = 0; i < propertyCount; i++)
for (var i = 0; i < properties.Length; i++)
{
var property = properties[i];
var bindingInfo = propertyBindingInfo![i];
Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/Mvc.TagHelpers/src/AttributeMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public static bool TryDetermineMode<TMode>(
var allAttributes = context.AllAttributes;
// Read interface .Count once rather than per iteration
var allAttributesCount = allAttributes.Count;
foreach (var modeInfo in modeInfos.AsSpan())
foreach (var modeInfo in modeInfos)
{
var requiredAttributes = modeInfo.Attributes;
// If there are fewer attributes present than required, one or more of them must be missing.
if (allAttributesCount >= requiredAttributes.Length &&
if (allAttributesCount >= requiredAttributes.Length &&
!HasMissingAttributes(allAttributes, requiredAttributes) &&
compare(result, modeInfo.Mode) <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Mvc.ViewFeatures/src/DefaultDisplayTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();

var content = new HtmlContentBuilder(modelExplorer.Metadata.Properties.Count);
foreach (var propertyExplorer in modelExplorer.PropertiesInternal.AsSpan())
foreach (var propertyExplorer in modelExplorer.PropertiesInternal)
{
var propertyMetadata = propertyExplorer.Metadata;
if (!ShouldShow(propertyExplorer, templateInfo))
Expand Down
17 changes: 4 additions & 13 deletions src/Mvc/Mvc.ViewFeatures/src/DefaultEditorTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();

var content = new HtmlContentBuilder(modelExplorer.Metadata.Properties.Count);
foreach (var propertyExplorer in modelExplorer.PropertiesInternal.AsSpan())
foreach (var propertyExplorer in modelExplorer.PropertiesInternal)
{
var propertyMetadata = propertyExplorer.Metadata;
if (!ShouldShow(propertyExplorer, templateInfo))
Expand Down Expand Up @@ -476,26 +476,17 @@ public override void Write(char value)

public override void Write(char[] buffer, int index, int count)
{
if (count > 0)
{
HasContent = true;
}
HasContent |= count > 0;
}

public override void Write(ReadOnlySpan<char> buffer)
{
if (!buffer.IsEmpty)
{
HasContent = true;
}
HasContent |= buffer.IsEmpty;
}

public override void Write(string value)
{
if (!string.IsNullOrEmpty(value))
{
HasContent = true;
}
HasContent |= !string.IsNullOrEmpty(value);
}
}

Expand Down

0 comments on commit 8877dbc

Please sign in to comment.