@@ -288,21 +288,22 @@ public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui
288288 public static void addDependenciesFromFolder (File projectFolder , Collection <File > dependencies ) {
289289 File dependencyFolder = new File (new File (projectFolder , "_build" ), "dependencies" );
290290 File [] depProjects = dependencyFolder .listFiles ();
291- if (depProjects != null ) {
292- for (File depFile : depProjects ) {
293- if (depFile .isDirectory ()) {
294- boolean b = true ;
295- for (File f : dependencies ) {
296- if (FileUtils .sameFile (f , depFile )) {
297- b = false ;
298- break ;
299- }
300- }
301- if (b ) {
302- dependencies .add (depFile );
303- }
291+ if (depProjects == null ) return ;
292+
293+ // keep behavior (FileUtils.sameFile), but avoid O(n*m) scanning
294+ List <File > existing = new ArrayList <>(dependencies );
295+
296+ outer :
297+ for (File depFile : depProjects ) {
298+ if (!depFile .isDirectory ()) continue ;
299+
300+ for (File f : existing ) {
301+ if (FileUtils .sameFile (f , depFile )) {
302+ continue outer ;
304303 }
305304 }
305+ dependencies .add (depFile );
306+ existing .add (depFile );
306307 }
307308 }
308309
@@ -615,35 +616,27 @@ private void addJassHotCodeReloadCode() {
615616 }
616617
617618 @ NotNull
618- private ImFunction findNative (String funcName , WPos trace ) {
619+ private ImFunction findFunctionInternal (String funcName , WPos trace , boolean mustBeNative ) {
620+ Preconditions .checkNotNull (imProg );
619621 for (ImFunction func : imProg .getFunctions ()) {
620- if (func .isNative ()) {
621- if (func .getName ().equals (funcName )) {
622- return Optional .of (func )
623- .orElseGet (() -> {
624- throw new CompileError (trace , "Could not find native " + funcName );
625- });
626- }
622+ if (func .getName ().equals (funcName ) && (!mustBeNative || func .isNative ())) {
623+ return func ;
627624 }
628625 }
629- return Optional .<ImFunction >empty ()
630- .orElseThrow (() -> new CompileError (trace , "Could not find native " + funcName ));
626+ throw new CompileError (trace , "Could not find " + (mustBeNative ? "native " : "" ) + funcName );
627+ }
628+
629+ @ NotNull
630+ private ImFunction findNative (String funcName , WPos trace ) {
631+ return findFunctionInternal (funcName , trace , true );
631632 }
632633
633634 @ NotNull
634635 private ImFunction findFunction (String funcName , WPos trace ) {
635- for (ImFunction func : imProg .getFunctions ()) {
636- if (func .getName ().equals (funcName )) {
637- return Optional .of (func )
638- .orElseGet (() -> {
639- throw new CompileError (trace , "Could not find native " + funcName );
640- });
641- }
642- }
643- return Optional .<ImFunction >empty ()
644- .orElseThrow (() -> new CompileError (trace , "Could not find native " + funcName ));
636+ return findFunctionInternal (funcName , trace , false );
645637 }
646638
639+
647640 @ NotNull
648641 private ImFunctionCall callExtern (Element trace , CallType callType , String functionName , ImExpr ... arguments ) {
649642 ImFunction jhcrinit = JassIm .ImFunction (trace , functionName , JassIm .ImTypeVars (), JassIm .ImVars (), JassIm .ImVoid (), JassIm .ImVars (), JassIm .ImStmts (), Collections .singletonList (IS_EXTERN ));
0 commit comments