Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component name valid caching #529

Merged
merged 2 commits into from Apr 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/React.Core/ReactComponent.cs
Expand Up @@ -8,6 +8,7 @@
*/

using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Text.RegularExpressions;
using JavaScriptEngineSwitcher.Core;
Expand All @@ -21,6 +22,8 @@ namespace React
/// </summary>
public class ReactComponent : IReactComponent
{
private static readonly ConcurrentDictionary<string, bool> _componentNameValidCache = new ConcurrentDictionary<string, bool>(StringComparer.Ordinal);

/// <summary>
/// Regular expression used to validate JavaScript identifiers. Used to ensure component
/// names are valid.
Expand Down Expand Up @@ -220,13 +223,10 @@ protected virtual string GetComponentInitialiser()
/// <param name="componentName"></param>
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}'");
}
}

Expand Down