Skip to content

Commit 6607776

Browse files
authored
Minor optimizations (#2727)
1 parent 865ea42 commit 6607776

File tree

9 files changed

+14
-17
lines changed

9 files changed

+14
-17
lines changed

ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using AwesomeAssertions;
77
using ImperatorToCK3.CK3;
88
using ImperatorToCK3.CK3.Characters;
9-
using ImperatorToCK3.CK3.Cultures;
109
using ImperatorToCK3.CK3.Dynasties;
1110
using ImperatorToCK3.CK3.Religions;
1211
using ImperatorToCK3.CK3.Titles;
@@ -28,7 +27,6 @@
2827
using System.Collections.Generic;
2928
using System.Linq;
3029
using Xunit;
31-
using Culture = ImperatorToCK3.Imperator.Cultures.Culture;
3230

3331
namespace ImperatorToCK3.UnitTests.CK3.Characters;
3432

@@ -94,7 +92,7 @@ internal Character Build() {
9492
DNAFactory,
9593
new Date(867, 1, 1),
9694
config,
97-
unlocalizedImperatorNames: new HashSet<string>()
95+
unlocalizedImperatorNames: []
9896
);
9997
return character;
10098
}

ImperatorToCK3.UnitTests/CK3/Dynasties/DynastyTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using Xunit;
2424
using Character = ImperatorToCK3.CK3.Characters.Character;
2525
using System;
26-
using System.Collections.Generic;
2726
using CharacterCollection = ImperatorToCK3.Imperator.Characters.CharacterCollection;
2827

2928
// ReSharper disable StringLiteralTypo
@@ -91,7 +90,7 @@ public Character Build() {
9190
new DNAFactory(IRModFS, ck3ModFS),
9291
new Date(867, 1, 1),
9392
config,
94-
unlocalizedImperatorNames: new HashSet<string>()
93+
unlocalizedImperatorNames: []
9594
);
9695
return character;
9796
}

ImperatorToCK3/CK3/Characters/Character.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ internal Character(
374374
DNAFactory dnaFactory,
375375
Date dateOnConversion,
376376
Configuration config,
377-
ISet<string> unlocalizedImperatorNames
377+
ConcurrentHashSet<string> unlocalizedImperatorNames
378378
) {
379379
this.characters = characters;
380380

ImperatorToCK3/CK3/Characters/CharacterCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void ImportImperatorCharacter(
103103
DNAFactory dnaFactory,
104104
Date endDate,
105105
Configuration config,
106-
ISet<string> unlocalizedImperatorNames) {
106+
ConcurrentHashSet<string> unlocalizedImperatorNames) {
107107
// Create a new CK3 character.
108108
var newCharacter = new Character(
109109
irCharacter,

ImperatorToCK3/CK3/Religions/ReligionCollection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ Date date
325325
}
326326

327327
// Returns a dictionary with CK3 provinces that are mapped to Imperator provinces, grouped by faith.
328-
public static IDictionary<string, ISet<Province>> GetProvincesFromImperatorByFaith(ProvinceCollection ck3Provinces, Date date) {
329-
var provincesByFaith = new Dictionary<string, ISet<Province>>();
328+
public static Dictionary<string, HashSet<Province>> GetProvincesFromImperatorByFaith(ProvinceCollection ck3Provinces, Date date) {
329+
var provincesByFaith = new Dictionary<string, HashSet<Province>>();
330330

331331
foreach (var province in ck3Provinces) {
332332
var imperatorProvince = province.PrimaryImperatorProvince;
@@ -342,7 +342,7 @@ public static IDictionary<string, ISet<Province>> GetProvincesFromImperatorByFai
342342
if (provincesByFaith.TryGetValue(faith, out var set)) {
343343
set.Add(province);
344344
} else {
345-
provincesByFaith[faith] = new HashSet<Province> {province};
345+
provincesByFaith[faith] = [province];
346346
}
347347
}
348348

@@ -484,13 +484,13 @@ Date date
484484
title.SetHolder(character, date);
485485
}
486486

487-
private List<Title> GetDynamicHolySiteBaroniesForFaith(Faith faith, IDictionary<string, ISet<Province>> provincesByFaith) {
487+
private List<Title> GetDynamicHolySiteBaroniesForFaith(Faith faith, Dictionary<string, HashSet<Province>> provincesByFaith) {
488488
// Collect all Imperator territories that are mapped to this faith.
489-
ISet<Province> faithTerritories;
489+
HashSet<Province> faithTerritories;
490490
if (provincesByFaith.TryGetValue(faith.Id, out var set)) {
491491
faithTerritories = set;
492492
} else {
493-
faithTerritories = new HashSet<Province>();
493+
faithTerritories = [];
494494
}
495495

496496
// Split the territories into 2 sets: territories that have a holy site and territories that do not.

ImperatorToCK3/Imperator/Inventions/InventionsDB.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void LoadInventions(ModFilesystem irModFS) {
2929
inventionGroupsParser.ParseGameFolder("common/inventions", irModFS, "txt", recursive: true);
3030
}
3131

32-
public IEnumerable<string> GetActiveInventionIds(IList<bool> booleans) {
32+
public IEnumerable<string> GetActiveInventionIds(List<bool> booleans) {
3333
// Enumerate over the inventions and return the ones that are active (bool is true).
3434
foreach (var item in inventionIds.Select((inventionId, i) => new { i, inventionId })) {
3535
if (item.i < booleans.Count && booleans[item.i]) {

ImperatorToCK3/Mappers/Gene/MorphGeneTemplateMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace ImperatorToCK3.Mappers.Gene;
77

88
internal sealed class MorphGeneTemplateMapper {
9-
private readonly Dictionary<string, IList<Assignment>> templateMappings = []; // <geneName, <irTemplate, ck3Template>>
9+
private readonly Dictionary<string, List<Assignment>> templateMappings = []; // <geneName, <irTemplate, ck3Template>>
1010

1111
public MorphGeneTemplateMapper(string mappingsFilePath) {
1212
var parser = new Parser();

ImperatorToCK3/Mappers/Technology/InnovationMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void LogUnmappedInventions(InventionsDB inventionsDB, LocDB irLocDB) {
7373

7474
// TODO: ALSO LOG UNMAPPED CK3 MARTIAL AND CIVIC INNOVATIONS
7575

76-
public void RemoveMappingsWithInvalidInnovations(ISet<string> innovationIds) {
76+
public void RemoveMappingsWithInvalidInnovations(HashSet<string> innovationIds) {
7777
int removedCount = 0;
7878

7979
removedCount += innovationLinks

ImperatorToCK3/Outputter/BookmarkOutputter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private static FrozenSet<ulong> GetColorableImpassablesExceptMapEdgeProvinces(Ma
279279
return mapData.ColorableImpassableProvinceIds.Except(mapData.MapEdgeProvinceIds).ToFrozenSet();
280280
}
281281

282-
private static HashSet<ulong> GetImpassableProvincesToColor(MapData mapData, ISet<ulong> heldProvinceIds) {
282+
private static HashSet<ulong> GetImpassableProvincesToColor(MapData mapData, HashSet<ulong> heldProvinceIds) {
283283
var provinceIdsToColor = new HashSet<ulong>(heldProvinceIds);
284284
var impassableIds = GetColorableImpassablesExceptMapEdgeProvinces(mapData);
285285
foreach (ulong impassableId in impassableIds) {

0 commit comments

Comments
 (0)