Skip to content

Commit 62838e5

Browse files
authored
Merge pull request #122 from gadfly3173/fix/dictionary-exception
fix: avoid potential IndexOutOfRangeException in Models.User
2 parents 449da31 + 3b166a5 commit 62838e5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Models/User.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Concurrent;
22

33
namespace SourceGit.Models
44
{
@@ -36,11 +36,11 @@ public static User FindOrAdd(string data)
3636
var email = data.Substring(nameEndIdx + 1);
3737

3838
User user = new User() { Name = name, Email = email };
39-
_caches.Add(data, user);
39+
_caches.TryAdd(data, user);
4040
return user;
4141
}
4242
}
4343

44-
private static Dictionary<string, User> _caches = new Dictionary<string, User>();
44+
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
4545
}
4646
}

0 commit comments

Comments
 (0)