Skip to content

Commit 5155e11

Browse files
Two minor perf tweaks in CORS and Localization middleware (dotnet#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.
1 parent 9d9784d commit 5155e11

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/Middleware/CORS/src/Infrastructure/CorsPolicy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public bool AllowAnyHeader
3030
{
3131
get
3232
{
33-
if (Headers == null || Headers.Count != 1 || Headers.Count == 1 && Headers[0] != "*")
33+
if (Headers == null || Headers.Count != 1 || Headers[0] != "*")
3434
{
3535
return false;
3636
}
@@ -46,7 +46,7 @@ public bool AllowAnyMethod
4646
{
4747
get
4848
{
49-
if (Methods == null || Methods.Count != 1 || Methods.Count == 1 && Methods[0] != "*")
49+
if (Methods == null || Methods.Count != 1 || Methods[0] != "*")
5050
{
5151
return false;
5252
}
@@ -62,7 +62,7 @@ public bool AllowAnyOrigin
6262
{
6363
get
6464
{
65-
if (Origins == null || Origins.Count != 1 || Origins.Count == 1 && Origins[0] != "*")
65+
if (Origins == null || Origins.Count != 1 || Origins[0] != "*")
6666
{
6767
return false;
6868
}

src/Middleware/Localization/src/CookieRequestCultureProvider.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Http;
7-
using Microsoft.Extensions.Internal;
87

98
namespace Microsoft.AspNetCore.Localization
109
{
@@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Localization
1312
/// </summary>
1413
public class CookieRequestCultureProvider : RequestCultureProvider
1514
{
16-
private static readonly char[] _cookieSeparator = new[] { '|' };
15+
private static readonly char _cookieSeparator = '|';
1716
private static readonly string _culturePrefix = "c=";
1817
private static readonly string _uiCulturePrefix = "uic=";
1918

@@ -60,9 +59,7 @@ public static string MakeCookieValue(RequestCulture requestCulture)
6059
throw new ArgumentNullException(nameof(requestCulture));
6160
}
6261

63-
var seperator = _cookieSeparator[0].ToString();
64-
65-
return string.Join(seperator,
62+
return string.Join(_cookieSeparator,
6663
$"{_culturePrefix}{requestCulture.Culture.Name}",
6764
$"{_uiCulturePrefix}{requestCulture.UICulture.Name}");
6865
}

0 commit comments

Comments
 (0)