Skip to content

Commit 8877dbc

Browse files
committed
PR feedback
1 parent 52daca7 commit 8877dbc

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/Mvc/Mvc.Core/src/Controllers/ControllerBinderDelegateProvider.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ internal static class ControllerBinderDelegateProvider
5757
return null;
5858
}
5959

60-
var parameters = actionDescriptor.Parameters as List<ParameterDescriptor> ?? actionDescriptor.Parameters.ToList();
61-
var properties = actionDescriptor.BoundProperties as List<ParameterDescriptor> ?? actionDescriptor.BoundProperties.ToList();
60+
var parameters = actionDescriptor.Parameters switch
61+
{
62+
List<ParameterDescriptor> list => list.ToArray(),
63+
_ => actionDescriptor.Parameters.ToArray()
64+
};
65+
66+
var properties = actionDescriptor.BoundProperties switch
67+
{
68+
List<ParameterDescriptor> list => list.ToArray(),
69+
_ => actionDescriptor.BoundProperties.ToArray()
70+
};
6271

6372
return Bind;
6473

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

7382
Debug.Assert(valueProvider is not null);
7483

75-
var parameterCount = parameters.Count;
76-
for (var i = 0; i < parameterCount; i++)
84+
for (var i = 0; i < parameters.Length; i++)
7785
{
7886
var parameter = parameters[i];
7987
var bindingInfo = parameterBindingInfo![i];
@@ -99,8 +107,7 @@ async Task Bind(ControllerContext controllerContext, object controller, Dictiona
99107
}
100108
}
101109

102-
var propertyCount = properties.Count;
103-
for (var i = 0; i < propertyCount; i++)
110+
for (var i = 0; i < properties.Length; i++)
104111
{
105112
var property = properties[i];
106113
var bindingInfo = propertyBindingInfo![i];

src/Mvc/Mvc.TagHelpers/src/AttributeMatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public static bool TryDetermineMode<TMode>(
4949
var allAttributes = context.AllAttributes;
5050
// Read interface .Count once rather than per iteration
5151
var allAttributesCount = allAttributes.Count;
52-
foreach (var modeInfo in modeInfos.AsSpan())
52+
foreach (var modeInfo in modeInfos)
5353
{
5454
var requiredAttributes = modeInfo.Attributes;
5555
// If there are fewer attributes present than required, one or more of them must be missing.
56-
if (allAttributesCount >= requiredAttributes.Length &&
56+
if (allAttributesCount >= requiredAttributes.Length &&
5757
!HasMissingAttributes(allAttributes, requiredAttributes) &&
5858
compare(result, modeInfo.Mode) <= 0)
5959
{

src/Mvc/Mvc.ViewFeatures/src/DefaultDisplayTemplates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
212212
var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();
213213

214214
var content = new HtmlContentBuilder(modelExplorer.Metadata.Properties.Count);
215-
foreach (var propertyExplorer in modelExplorer.PropertiesInternal.AsSpan())
215+
foreach (var propertyExplorer in modelExplorer.PropertiesInternal)
216216
{
217217
var propertyMetadata = propertyExplorer.Metadata;
218218
if (!ShouldShow(propertyExplorer, templateInfo))

src/Mvc/Mvc.ViewFeatures/src/DefaultEditorTemplates.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
255255
var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();
256256

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

477477
public override void Write(char[] buffer, int index, int count)
478478
{
479-
if (count > 0)
480-
{
481-
HasContent = true;
482-
}
479+
HasContent |= count > 0;
483480
}
484481

485482
public override void Write(ReadOnlySpan<char> buffer)
486483
{
487-
if (!buffer.IsEmpty)
488-
{
489-
HasContent = true;
490-
}
484+
HasContent |= buffer.IsEmpty;
491485
}
492486

493487
public override void Write(string value)
494488
{
495-
if (!string.IsNullOrEmpty(value))
496-
{
497-
HasContent = true;
498-
}
489+
HasContent |= !string.IsNullOrEmpty(value);
499490
}
500491
}
501492

0 commit comments

Comments
 (0)