@@ -37,53 +37,25 @@ public ModPass(string name)
3737 public void AddLastPatch ( IPatch patch ) => lastPass . Add ( patch ?? throw new ArgumentNullException ( nameof ( patch ) ) ) ;
3838 }
3939
40- private class ModPassCollection : IEnumerable < ModPass >
41- {
42- private readonly ModPass [ ] passesArray ;
43- private readonly Dictionary < string , ModPass > passesDict ;
44-
45- public ModPassCollection ( IEnumerable < string > modList )
46- {
47- int count = modList . Count ( ) ;
48- passesArray = new ModPass [ count ] ;
49- passesDict = new Dictionary < string , ModPass > ( count ) ;
50-
51- int i = 0 ;
52- foreach ( string mod in modList )
53- {
54- ModPass pass = new ModPass ( mod ) ;
55- passesArray [ i ] = pass ;
56- passesDict . Add ( mod . ToLowerInvariant ( ) , pass ) ;
57- i ++ ;
58- }
59- }
60-
61- public ModPass this [ string name ] => passesDict [ name . ToLowerInvariant ( ) ] ;
62- public ModPass this [ int index ] => passesArray [ index ] ;
63-
64- public bool HasMod ( string name ) => passesDict . ContainsKey ( name . ToLowerInvariant ( ) ) ;
65-
66- public int Count => passesArray . Length ;
67-
68- public ArrayEnumerator < ModPass > GetEnumerator ( ) => new ArrayEnumerator < ModPass > ( passesArray ) ;
69- IEnumerator < ModPass > IEnumerable < ModPass > . GetEnumerator ( ) => GetEnumerator ( ) ;
70- IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
71- }
72-
7340 private readonly Pass insertPatches = new Pass ( ":INSERT (initial)" ) ;
7441 private readonly Pass firstPatches = new Pass ( ":FIRST" ) ;
7542 private readonly Pass legacyPatches = new Pass ( ":LEGACY (default)" ) ;
7643 private readonly Pass finalPatches = new Pass ( ":FINAL" ) ;
7744
78- private readonly ModPassCollection modPasses ;
45+ private readonly SortedDictionary < string , ModPass > modPasses = new SortedDictionary < string , ModPass > ( StringComparer . InvariantCultureIgnoreCase ) ;
7946 private readonly SortedDictionary < string , Pass > lastPasses = new SortedDictionary < string , Pass > ( StringComparer . InvariantCultureIgnoreCase ) ;
8047
8148 public PatchList ( IEnumerable < string > modList , IEnumerable < IPatch > patches , IPatchProgress progress )
8249 {
83- modPasses = new ModPassCollection ( modList ?? throw new ArgumentNullException ( nameof ( modList ) ) ) ;
50+ if ( modList == null ) throw new ArgumentNullException ( nameof ( modList ) ) ;
8451 if ( patches == null ) throw new ArgumentNullException ( nameof ( patches ) ) ;
8552 if ( progress == null ) throw new ArgumentNullException ( nameof ( progress ) ) ;
8653
54+ foreach ( string mod in modList )
55+ {
56+ modPasses . Add ( mod , new ModPass ( mod ) ) ;
57+ }
58+
8759 foreach ( IPatch patch in patches )
8860 {
8961 if ( patch . PassSpecifier is InsertPassSpecifier )
@@ -141,7 +113,7 @@ public IEnumerator<IPass> GetEnumerator()
141113 yield return firstPatches ;
142114 yield return legacyPatches ;
143115
144- foreach ( ModPass modPass in modPasses )
116+ foreach ( ModPass modPass in modPasses . Values )
145117 {
146118 yield return modPass . beforePass ;
147119 yield return modPass . forPass ;
@@ -162,7 +134,7 @@ private void EnsureMod(string mod)
162134 {
163135 if ( mod == null ) throw new ArgumentNullException ( nameof ( mod ) ) ;
164136 if ( mod == string . Empty ) throw new ArgumentException ( "can't be empty" , nameof ( mod ) ) ;
165- if ( ! modPasses . HasMod ( mod ) ) throw new KeyNotFoundException ( $ "Mod '{ mod } ' not found") ;
137+ if ( ! modPasses . ContainsKey ( mod ) ) throw new KeyNotFoundException ( $ "Mod '{ mod } ' not found") ;
166138 }
167139 }
168140}
0 commit comments