@@ -36,7 +36,7 @@ internal class CompilerService
3636 private readonly string _filePath ;
3737 private string _remoteName ;
3838 private float _startTime ;
39- private string [ ] _preprocessor ;
39+ private HashSet < string > _preprocessor ;
4040 private readonly string _pipeName ;
4141
4242 public bool Installed => File . Exists ( _filePath ) ;
@@ -110,25 +110,24 @@ private void ExpireFileCache()
110110
111111 internal bool Precheck ( )
112112 {
113- List < string > preprocessorList = new List < string >
113+ HashSet < string > preprocessors = new ( )
114114 {
115115 "OXIDE" ,
116116 "OXIDEMOD"
117117 } ;
118118
119- Extension game = Interface . Oxide . GetAllExtensions ( ) . SingleOrDefault ( e => e . IsGameExtension ) ;
120-
119+ Extension ? game = Interface . Oxide . GetAllExtensions ( ) . SingleOrDefault ( e => e . IsGameExtension ) ;
121120 if ( game != null )
122121 {
123122 string name = game . Name . ToUpperInvariant ( ) ;
124123 string branch = game . Branch ? . ToUpperInvariant ( ) ?? "PUBLIC" ;
125- preprocessorList . Add ( EscapeSymbolName ( name ) ) ;
126- preprocessorList . Add ( EscapeSymbolName ( name + "_" + branch ) ) ;
124+ preprocessors . Add ( EscapeSymbolName ( name ) ) ;
125+ preprocessors . Add ( EscapeSymbolName ( name + "_" + branch ) ) ;
127126
128127 if ( game . Version != default )
129128 {
130- preprocessorList . Add ( EscapeSymbolName ( name + "_" + game . Version ) ) ;
131- preprocessorList . Add ( EscapeSymbolName ( name + "_" + game . Version + "_" + branch ) ) ;
129+ preprocessors . Add ( EscapeSymbolName ( name + "_" + game . Version ) ) ;
130+ preprocessors . Add ( EscapeSymbolName ( name + "_" + game . Version + "_" + branch ) ) ;
132131 }
133132 }
134133
@@ -139,39 +138,40 @@ internal bool Precheck()
139138 string prefix = $ "{ extension . Name . ToUpper ( ) } _EXT";
140139 foreach ( string directive in extension . GetPreprocessorDirectives ( ) )
141140 {
142- if ( ! extension . IsGameExtension && ! extension . IsCoreExtension && ! directive . StartsWith ( prefix ) )
141+ if ( extension is { IsGameExtension : false , IsCoreExtension : false } && ! directive . StartsWith ( prefix ) )
143142 {
144143 Interface . Oxide . LogWarning ( "Missing extension preprocessor prefix '{0}' for directive '{1}' (by extension '{2}')" , prefix , directive , extension . Name ) ;
145144 }
146145
147- preprocessorList . Add ( EscapeSymbolName ( directive ) ) ;
146+ preprocessors . Add ( EscapeSymbolName ( directive ) ) ;
148147 }
149148 }
150- catch ( Exception ex )
149+ catch ( Exception exception )
151150 {
152- Interface . Oxide . LogException ( $ "An error occurred processing preprocessor directives for extension `{ extension . Name } `", ex ) ;
151+ Interface . Oxide . LogException ( $ "An error occurred processing preprocessor directives for extension `{ extension . Name } `", exception ) ;
153152 }
154153 }
155154
156155#if DEBUG
157- preprocessorList . Add ( "DEBUG" ) ;
156+ preprocessors . Add ( "DEBUG" ) ;
158157#endif
159158
160- if ( Interface . Oxide . Config . Compiler . PreprocessorDirectives . Count > 0 )
159+ int preprocessorCount = Interface . Oxide . Config . Compiler . PreprocessorDirectives . Count ;
160+ for ( int i = 0 ; i < preprocessorCount ; i ++ )
161161 {
162- preprocessorList . AddRange ( Interface . Oxide . Config . Compiler . PreprocessorDirectives ) ;
162+ preprocessors . Add ( Interface . Oxide . Config . Compiler . PreprocessorDirectives [ i ] ) ;
163163 }
164164
165165 if ( Interface . Oxide . Config . Compiler . Publicize ?? false )
166166 {
167167 EnvironmentHelper . SetVariable ( "AllowPublicize" , "true" , force : true ) ;
168- preprocessorList . Add ( "OXIDE_PUBLICIZED" ) ;
168+ preprocessors . Add ( "OXIDE_PUBLICIZED" ) ;
169169 }
170170
171- _preprocessor = preprocessorList . Distinct ( ) . ToArray ( ) ;
171+ _preprocessor = preprocessors ;
172172
173173#if DEBUG
174- Log ( LogType . Debug , $ "Preprocessors are: { string . Join ( ", " , _preprocessor ) } ") ;
174+ Log ( LogType . Debug , $ "Preprocessors are: { _preprocessor . JoinValues ( ", " ) } ") ;
175175#endif
176176
177177// #if !DEBUG
@@ -554,7 +554,6 @@ private void EnqueueCompilation(Compilation compilation)
554554 List < CompilerFile > sourceFiles = PoolFactory < List < CompilerFile > > . Shared . Take ( ) ;
555555 try
556556 {
557-
558557 foreach ( CompilablePlugin plugin in compilation . plugins )
559558 {
560559 string name = Path . GetFileName ( plugin . ScriptPath ?? plugin . ScriptName ) ;
0 commit comments