Skip to content

Commit 3a4e0b0

Browse files
authored
Use GeneratedRegex, FrozenSet, new Lock object & static (#19872)
1 parent e5d1c67 commit 3a4e0b0

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

src/Umbraco.Cms.Api.Management/ServerEvents/UserConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class UserConnectionManager : IUserConnectionManager
77
{
88
// We use a normal dictionary instead of ConcurrentDictionary, since we need to lock the set anyways.
99
private readonly Dictionary<Guid, HashSet<string>> _connections = new();
10-
private readonly object _lock = new();
10+
private readonly Lock _lock = new();
1111

1212
/// <inheritdoc/>
1313
public ISet<string> GetConnections(Guid userKey)

src/Umbraco.Core/Extensions/StringExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.ComponentModel.DataAnnotations;
66
using System.Diagnostics.CodeAnalysis;
77
using System.Globalization;
8-
using System.Runtime.InteropServices;
98
using System.Security.Cryptography;
109
using System.Text;
1110
using System.Text.RegularExpressions;

src/Umbraco.Core/Routing/SiteDomainMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void Clear()
6565
}
6666
}
6767

68-
private IEnumerable<string> ValidateDomains(IEnumerable<string> domains) =>
68+
private static IEnumerable<string> ValidateDomains(IEnumerable<string> domains) =>
6969
// must use authority format w/optional scheme and port, but no path
7070
// any domain should appear only once
7171
domains.Select(domain =>
@@ -368,7 +368,7 @@ public virtual IEnumerable<DomainAndUri> MapDomains(IReadOnlyCollection<DomainAn
368368
// therefore it is safe to return and exit the configuration lock
369369
}
370370

371-
private DomainAndUri? MapDomain(
371+
private static DomainAndUri? MapDomain(
372372
IReadOnlyCollection<DomainAndUri> domainAndUris,
373373
Dictionary<string, string[]>? qualifiedSites,
374374
string currentAuthority,

src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Globalization;
22
using System.Text.RegularExpressions;
33
using Umbraco.Cms.Core.Routing;
4-
using Umbraco.Cms.Core.Web;
54

65
namespace Umbraco.Cms.Core.Templates;
76

@@ -84,7 +83,7 @@ public string EnsureInternalLinks(string text)
8483

8584
// under normal circumstances, the type attribute is preceded by a space
8685
// to cover the rare occasion where it isn't, we first replace with a space and then without.
87-
private string StripTypeAttributeFromTag(string tag, string type) =>
86+
private static string StripTypeAttributeFromTag(string tag, string type) =>
8887
tag.Replace($" type=\"{type}\"", string.Empty)
8988
.Replace($"type=\"{type}\"", string.Empty);
9089

src/Umbraco.Web.Common/Filters/ModelBindingExceptionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void OnException(ExceptionContext filterContext)
8585
/// The application is in an unstable state and is going to be restarted. The application is restarting now.
8686
/// </para>
8787
/// </remarks>
88-
private bool IsMessageAboutTheSameModelType(string exceptionMessage)
88+
private static bool IsMessageAboutTheSameModelType(string exceptionMessage)
8989
{
9090
MatchCollection matches = GetPublishedModelsTypesRegex.Matches(exceptionMessage);
9191

src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Collections.Frozen;
23
using System.Reflection;
34
using System.Reflection.Emit;
45
using System.Text;
@@ -21,12 +22,24 @@
2122

2223
namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto
2324
{
24-
internal sealed class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObject, IDisposable
25+
internal sealed partial class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObject, IDisposable
2526
{
26-
private static readonly Regex s_usingRegex = new Regex("^using(.*);", RegexOptions.Compiled | RegexOptions.Multiline);
27-
private static readonly Regex s_aattrRegex = new Regex("^\\[assembly:(.*)\\]", RegexOptions.Compiled | RegexOptions.Multiline);
28-
private static readonly Regex s_assemblyVersionRegex = new Regex("AssemblyVersion\\(\"[0-9]+.[0-9]+.[0-9]+.[0-9]+\"\\)", RegexOptions.Compiled);
29-
private static readonly string[] s_ourFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err", "Compiled" };
27+
private static readonly Regex s_usingRegex = GetUsingRegex();
28+
29+
[GeneratedRegex("^using(.*);", RegexOptions.Multiline | RegexOptions.Compiled)]
30+
private static partial Regex GetUsingRegex();
31+
32+
private static readonly Regex s_aattrRegex = GetAssemblyRegex();
33+
34+
[GeneratedRegex("^\\[assembly:(.*)\\]", RegexOptions.Multiline | RegexOptions.Compiled)]
35+
private static partial Regex GetAssemblyRegex();
36+
37+
private static readonly Regex s_assemblyVersionRegex = GetAssemblyVersionRegex();
38+
39+
[GeneratedRegex("AssemblyVersion\\(\"[0-9]+.[0-9]+.[0-9]+.[0-9]+\"\\)", RegexOptions.Compiled)]
40+
private static partial Regex GetAssemblyVersionRegex();
41+
42+
private static readonly FrozenSet<string> s_ourFiles = FrozenSet.Create("models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err", "Compiled");
3043
private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim();
3144
private readonly IProfilingLogger _profilingLogger;
3245
private readonly ILogger<InMemoryModelFactory> _logger;
@@ -797,7 +810,7 @@ private void WatcherOnChanged(object sender, FileSystemEventArgs args)
797810
// }
798811

799812
// always ignore our own file changes
800-
if (s_ourFiles.Contains(changed))
813+
if (changed != null && s_ourFiles.Contains(changed))
801814
{
802815
return;
803816
}

0 commit comments

Comments
 (0)