File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 88 */
99
1010using System ;
11+ using System . Collections . Concurrent ;
1112using System . Linq ;
1213using System . Text . RegularExpressions ;
1314using JavaScriptEngineSwitcher . Core ;
@@ -21,6 +22,8 @@ namespace React
2122 /// </summary>
2223 public class ReactComponent : IReactComponent
2324 {
25+ private static readonly ConcurrentDictionary < string , bool > _componentNameValidCache = new ConcurrentDictionary < string , bool > ( StringComparer . Ordinal ) ;
26+
2427 /// <summary>
2528 /// Regular expression used to validate JavaScript identifiers. Used to ensure component
2629 /// names are valid.
@@ -220,13 +223,10 @@ protected virtual string GetComponentInitialiser()
220223 /// <param name="componentName"></param>
221224 internal static void EnsureComponentNameValid ( string componentName )
222225 {
223- var isValid = componentName . Split ( '.' ) . All ( segment => _identifierRegex . IsMatch ( segment ) ) ;
226+ var isValid = _componentNameValidCache . GetOrAdd ( componentName , compName => compName . Split ( '.' ) . All ( segment => _identifierRegex . IsMatch ( segment ) ) ) ;
224227 if ( ! isValid )
225228 {
226- throw new ReactInvalidComponentException ( string . Format (
227- "Invalid component name '{0}'" ,
228- componentName
229- ) ) ;
229+ throw new ReactInvalidComponentException ( $ "Invalid component name '{ componentName } '") ;
230230 }
231231 }
232232
You can’t perform that action at this time.
0 commit comments