@@ -19,6 +19,7 @@ namespace ImperatorToCK3.CK3.Religions;
1919
2020internal sealed class ReligionCollection ( Title . LandedTitles landedTitles ) : IdObjectCollection < string , Religion > {
2121 private readonly Dictionary < string , OrderedSet < string > > replaceableHolySitesByFaith = [ ] ;
22+ private Dictionary < string , Faith > ? faithCache ;
2223 public IReadOnlyDictionary < string , OrderedSet < string > > ReplaceableHolySitesByFaith => replaceableHolySitesByFaith ;
2324 public IdObjectCollection < string , HolySite > HolySites { get ; } = [ ] ;
2425 public IdObjectCollection < string , DoctrineCategory > DoctrineCategories { get ; } = [ ] ;
@@ -30,6 +31,7 @@ public IEnumerable<Faith> Faiths {
3031 }
3132
3233 public void LoadReligions ( ModFilesystem ck3ModFS , ColorFactory colorFactory ) {
34+ faithCache = null ;
3335 var parser = new Parser ( ) ;
3436 parser . RegisterRegex ( CommonRegexes . String , ( religionReader , religionId ) => {
3537 var religion = new Religion ( religionId , religionReader , this , colorFactory ) ;
@@ -40,6 +42,7 @@ public void LoadReligions(ModFilesystem ck3ModFS, ColorFactory colorFactory) {
4042 }
4143
4244 public void LoadConverterFaiths ( string converterFaithsPath , ColorFactory colorFactory , Hash liquidVariables ) {
45+ faithCache = null ;
4346 OrderedSet < Faith > loadedConverterFaiths = [ ] ;
4447
4548 var parser = new Parser ( ) ;
@@ -228,13 +231,16 @@ public void LoadDoctrines(ModFilesystem ck3ModFS) {
228231 }
229232
230233 public Faith ? GetFaith ( string id ) {
231- foreach ( Religion religion in this ) {
232- if ( religion . Faiths . TryGetValue ( id , out var faith ) ) {
233- return faith ;
234+ if ( faithCache is null ) {
235+ faithCache = [ ] ;
236+ foreach ( var religion in this ) {
237+ foreach ( var faith in religion . Faiths ) {
238+ faithCache [ faith . Id ] = faith ;
239+ }
234240 }
235241 }
236242
237- return null ;
243+ return faithCache . TryGetValue ( id , out var result ) ? result : null ;
238244 }
239245
240246 private Title ? GetHolySiteBarony ( HolySite holySite ) {
0 commit comments