File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -25,20 +25,14 @@ public override int GetHashCode()
2525
2626 public static User FindOrAdd ( string data )
2727 {
28- if ( _caches . TryGetValue ( data , out var value ) )
28+ return _caches . GetOrAdd ( data , key =>
2929 {
30- return value ;
31- }
32- else
33- {
34- var nameEndIdx = data . IndexOf ( '<' , System . StringComparison . Ordinal ) ;
35- var name = nameEndIdx >= 2 ? data . Substring ( 0 , nameEndIdx - 1 ) : string . Empty ;
36- var email = data . Substring ( nameEndIdx + 1 ) ;
37-
38- User user = new User ( ) { Name = name , Email = email } ;
39- _caches . TryAdd ( data , user ) ;
40- return user ;
41- }
30+ var nameEndIdx = key . IndexOf ( '<' , System . StringComparison . Ordinal ) ;
31+ var name = nameEndIdx >= 2 ? key . Substring ( 0 , nameEndIdx - 1 ) : string . Empty ;
32+ var email = key . Substring ( nameEndIdx + 1 ) ;
33+
34+ return new User ( ) { Name = name , Email = email } ;
35+ } ) ;
4236 }
4337
4438 private static ConcurrentDictionary < string , User > _caches = new ConcurrentDictionary < string , User > ( ) ;
You can’t perform that action at this time.
0 commit comments