diff --git a/src/React.Core/ReactComponent.cs b/src/React.Core/ReactComponent.cs index 012100403..481485b15 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(StringComparer.Ordinal); + /// /// 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}'"); } }