@@ -56,15 +56,16 @@ public boolean sourcesRequired() {
5656 }
5757
5858 private static VirtualFile asVirtualFile (SourceFile sourceFile , DelegatingReporter reporter ,
59- Map <String , VirtualFile > placeholders ) {
60- if (sourceFile .file () instanceof AbstractZincFile ) {
61- return ((AbstractZincFile ) sourceFile .file ()).underlying ();
59+ HashMap <AbstractFile , VirtualFile > lookup , Map <AbstractFile , VirtualFile > placeholders ) {
60+ VirtualFile maybeCached = lookup .get (sourceFile .file ());
61+ if (maybeCached != null ) {
62+ return maybeCached ;
6263 } else {
6364 return fallbackVirtualFile (reporter , sourceFile , placeholders );
6465 }
6566 }
6667
67- private static void reportMissingFile (DelegatingReporter reporter , dotty . tools . dotc . interfaces . SourceFile sourceFile ) {
68+ private static void reportMissingFile (DelegatingReporter reporter , SourceFile sourceFile ) {
6869 String underline = String .join ("" , Collections .nCopies (sourceFile .path ().length (), "^" ));
6970 String message =
7071 sourceFile .path () + ": Missing virtual file\n " +
@@ -74,12 +75,11 @@ private static void reportMissingFile(DelegatingReporter reporter, dotty.tools.d
7475 reporter .reportBasicWarning (message );
7576 }
7677
77- private static VirtualFile fallbackVirtualFile (DelegatingReporter reporter ,
78- dotty .tools .dotc .interfaces .SourceFile sourceFile ,
79- Map <String , VirtualFile > placeholders ) {
80- return placeholders .computeIfAbsent (sourceFile .path (), path -> {
78+ private static VirtualFile fallbackVirtualFile (DelegatingReporter reporter , SourceFile sourceFile ,
79+ Map <AbstractFile , VirtualFile > placeholders ) {
80+ return placeholders .computeIfAbsent (sourceFile .file (), path -> {
8181 reportMissingFile (reporter , sourceFile );
82- if (sourceFile .jfile ().isPresent () )
82+ if (sourceFile .file ().jpath () != null )
8383 return new BasicPathBasedFile (sourceFile );
8484 else
8585 return new PlaceholderVirtualFile (sourceFile );
@@ -92,35 +92,30 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
9292 Arrays .sort (sortedSources , (x0 , x1 ) -> x0 .id ().compareTo (x1 .id ()));
9393
9494 ListBuffer <AbstractFile > sourcesBuffer = new ListBuffer <>();
95- dotty . tools . dotc . util . HashSet <AbstractFile > sourcesSet = new dotty . tools . dotc . util . HashSet <>(8 , 2 );
95+ HashMap <AbstractFile , VirtualFile > lookup = new HashMap <>(sources . length , 0.25f );
9696
9797 for (int i = 0 ; i < sources .length ; i ++) {
9898 VirtualFile source = sortedSources [i ];
9999 AbstractFile abstractFile = asDottyFile (source );
100100 sourcesBuffer .append (abstractFile );
101- sourcesSet .put (abstractFile );
101+ lookup .put (abstractFile , source );
102102 }
103103
104- HashMap <String , VirtualFile > placeholders = new HashMap <>();
104+ HashMap <AbstractFile , VirtualFile > placeholders = new HashMap <>();
105105
106106 DelegatingReporter reporter = new DelegatingReporter (delegate , (self , sourceFile ) ->
107- asVirtualFile (sourceFile , self , placeholders ).id ());
107+ asVirtualFile (sourceFile , self , lookup , placeholders ).id ());
108108
109- IncrementalCallback incCallback = new IncrementalCallback (callback , sourceFile -> {
110- if (sourceFile instanceof SourceFile ) {
111- return asVirtualFile (((SourceFile ) sourceFile ), reporter , placeholders );
112- } else {
113- return fallbackVirtualFile (reporter , sourceFile , placeholders );
114- }
115- });
109+ IncrementalCallback incCallback = new IncrementalCallback (callback , sourceFile ->
110+ asVirtualFile (sourceFile , reporter , lookup , placeholders )
111+ );
116112
117113 try {
118114 log .debug (this ::infoOnCachedCompiler );
119115
120116 Contexts .Context initialCtx = initCtx ()
121117 .fresh ()
122118 .setReporter (reporter )
123- .setZincInitialFiles (sourcesSet )
124119 .setIncCallback (incCallback );
125120
126121 Contexts .Context context = setup (args , initialCtx ).map (t -> t ._2 ).getOrElse (() -> initialCtx );
0 commit comments