Two minor perf tweaks in CORS and Localization middleware (#23190)

* Use char instead of char[] for string.Split

Use the newer overload for string.Split() that accepts a char instead of creating a char array.

* Remove redundant bounds check

Remove redundant bounds check for count of exactly 1 as that has already been checked to be true by the previous check.
This commit is contained in:
Martin Costello 2020-06-24 15:17:33 +01:00 committed by GitHub
parent 9d9784d271
commit 5155e11120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
{
get
{
if (Headers == null || Headers.Count != 1 || Headers.Count == 1 && Headers[0] != "*")
if (Headers == null || Headers.Count != 1 || Headers[0] != "*")
{
return false;
}
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
{
get
{
if (Methods == null || Methods.Count != 1 || Methods.Count == 1 && Methods[0] != "*")
if (Methods == null || Methods.Count != 1 || Methods[0] != "*")
{
return false;
}
@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
{
get
{
if (Origins == null || Origins.Count != 1 || Origins.Count == 1 && Origins[0] != "*")
if (Origins == null || Origins.Count != 1 || Origins[0] != "*")
{
return false;
}

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Localization
{
@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Localization
/// </summary>
public class CookieRequestCultureProvider : RequestCultureProvider
{
private static readonly char[] _cookieSeparator = new[] { '|' };
private static readonly char _cookieSeparator = '|';
private static readonly string _culturePrefix = "c=";
private static readonly string _uiCulturePrefix = "uic=";
@ -60,9 +59,7 @@ namespace Microsoft.AspNetCore.Localization
throw new ArgumentNullException(nameof(requestCulture));
}
var seperator = _cookieSeparator[0].ToString();
return string.Join(seperator,
return string.Join(_cookieSeparator,
$"{_culturePrefix}{requestCulture.Culture.Name}",
$"{_uiCulturePrefix}{requestCulture.UICulture.Name}");
}