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:
parent
9d9784d271
commit
5155e11120
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Headers == null || Headers.Count != 1 || Headers.Count == 1 && Headers[0] != "*")
|
if (Headers == null || Headers.Count != 1 || Headers[0] != "*")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Methods == null || Methods.Count != 1 || Methods.Count == 1 && Methods[0] != "*")
|
if (Methods == null || Methods.Count != 1 || Methods[0] != "*")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Origins == null || Origins.Count != 1 || Origins.Count == 1 && Origins[0] != "*")
|
if (Origins == null || Origins.Count != 1 || Origins[0] != "*")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Internal;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Localization
|
namespace Microsoft.AspNetCore.Localization
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Localization
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CookieRequestCultureProvider : RequestCultureProvider
|
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 _culturePrefix = "c=";
|
||||||
private static readonly string _uiCulturePrefix = "uic=";
|
private static readonly string _uiCulturePrefix = "uic=";
|
||||||
|
|
||||||
|
|
@ -60,9 +59,7 @@ namespace Microsoft.AspNetCore.Localization
|
||||||
throw new ArgumentNullException(nameof(requestCulture));
|
throw new ArgumentNullException(nameof(requestCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
var seperator = _cookieSeparator[0].ToString();
|
return string.Join(_cookieSeparator,
|
||||||
|
|
||||||
return string.Join(seperator,
|
|
||||||
$"{_culturePrefix}{requestCulture.Culture.Name}",
|
$"{_culturePrefix}{requestCulture.Culture.Name}",
|
||||||
$"{_uiCulturePrefix}{requestCulture.UICulture.Name}");
|
$"{_uiCulturePrefix}{requestCulture.UICulture.Name}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue