Skip to content

Commit 40692ea

Browse files
authored
Prevent possible multiple enumeration (#423) #patch
1 parent 71ede3e commit 40692ea

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ImperatorToCK3/Imperator/Countries/RulerTerm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public RulerTerm(BufferedReader prehistoryRulerReader, Countries countries) {
6767
if (tagToCountryCache.TryGetValue(tag, out var cachedCountry)) {
6868
PreImperatorRuler.Country = cachedCountry;
6969
} else {
70-
var matchingCountries = countries.Values.Where(c => c.Tag == tag);
71-
if (matchingCountries.Count() != 1) {
70+
var matchingCountries = countries.Values.Where(c => c.Tag == tag).ToArray();
71+
if (matchingCountries.Length != 1) {
7272
Logger.Warn($"Pre-Imperator ruler has wrong tag: {tag}!");
7373
return;
7474
}
75-
var countryId = matchingCountries.First().Id;
75+
var countryId = matchingCountries[0].Id;
7676
PreImperatorRuler.Country = countries[countryId];
7777
tagToCountryCache.Add(tag, PreImperatorRuler.Country);
7878
}

0 commit comments

Comments
 (0)