From 9eac24b330cce8b72a7c68be73bd2e35e03c5e49 Mon Sep 17 00:00:00 2001 From: Daniil Sokolyuk Date: Sun, 8 Apr 2018 19:00:19 +0300 Subject: [PATCH 1/2] component name valid cache --- src/React.Core/ReactComponent.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/React.Core/ReactComponent.cs b/src/React.Core/ReactComponent.cs index 012100403..c9080a6ce 100644 --- a/src/React.Core/ReactComponent.cs +++ b/src/React.Core/ReactComponent.cs @@ -8,6 +8,7 @@ */ using System; +using System.Collections.Concurrent; using System.Linq; using System.Text.RegularExpressions; using JavaScriptEngineSwitcher.Core; @@ -21,6 +22,8 @@ namespace React /// public class ReactComponent : IReactComponent { + private static readonly ConcurrentDictionary _componentNameValidCache = new ConcurrentDictionary(); + /// /// Regular expression used to validate JavaScript identifiers. Used to ensure component /// names are valid. @@ -220,13 +223,10 @@ protected virtual string GetComponentInitialiser() /// internal static void EnsureComponentNameValid(string componentName) { - var isValid = componentName.Split('.').All(segment => _identifierRegex.IsMatch(segment)); + var isValid = _componentNameValidCache.GetOrAdd(componentName, compName => compName.Split('.').All(segment => _identifierRegex.IsMatch(segment))); if (!isValid) { - throw new ReactInvalidComponentException(string.Format( - "Invalid component name '{0}'", - componentName - )); + throw new ReactInvalidComponentException($"Invalid component name '{componentName}'"); } } From 249a8bdfd9ad9f4a5476eb0530f2d52e0a68fe07 Mon Sep 17 00:00:00 2001 From: Daniil Sokolyuk Date: Sun, 8 Apr 2018 19:46:38 +0300 Subject: [PATCH 2/2] ordinal comparer for better performance --- src/React.Core/ReactComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/React.Core/ReactComponent.cs b/src/React.Core/ReactComponent.cs index c9080a6ce..481485b15 100644 --- a/src/React.Core/ReactComponent.cs +++ b/src/React.Core/ReactComponent.cs @@ -22,7 +22,7 @@ namespace React /// public class ReactComponent : IReactComponent { - private static readonly ConcurrentDictionary _componentNameValidCache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary _componentNameValidCache = new ConcurrentDictionary(StringComparer.Ordinal); /// /// Regular expression used to validate JavaScript identifiers. Used to ensure component pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy