@@ -138,8 +138,8 @@ class DeclarationsContext {
138138 /// Packages are sorted so that inner packages are before outer.
139139 final List <_Package > _packages = [];
140140
141- /// The list of paths of all files inside the context.
142- final List <String > _contextPathList = [] ;
141+ /// The set of paths of all files inside the context.
142+ final Set <String > _contextPathSet = {} ;
143143
144144 /// The list of paths of all SDK libraries.
145145 final List <String > _sdkLibraryPathList = [];
@@ -210,7 +210,7 @@ class DeclarationsContext {
210210 _addKnownLibraries (dependencyLibraries);
211211 }
212212
213- var contextPathList = < String > [] ;
213+ Iterable <String > contextPaths ;
214214 if (! _analysisContext.contextRoot.workspace.isBlaze) {
215215 _Package ? package;
216216 for (var candidatePackage in _packages) {
@@ -221,9 +221,10 @@ class DeclarationsContext {
221221 }
222222
223223 if (package != null ) {
224+ List <String > contextPathList = contextPaths = [];
224225 var containingFolder = package.folderInRootContaining (path);
225226 if (containingFolder != null ) {
226- for (var contextPath in _contextPathList ) {
227+ for (var contextPath in _contextPathSet ) {
227228 // `lib/` can see only libraries in `lib/`.
228229 // `test/` can see libraries in `lib/` and in `test/`.
229230 if (package.containsInLib (contextPath) ||
@@ -234,17 +235,17 @@ class DeclarationsContext {
234235 }
235236 } else {
236237 // Not in a package, include all libraries of the context.
237- contextPathList = _contextPathList ;
238+ contextPaths = _contextPathSet ;
238239 }
239240 } else {
240241 // In Blaze workspaces, consider declarations from the entire context
241- contextPathList = _contextPathList ;
242+ contextPaths = _contextPathSet ;
242243 }
243244
244245 var contextLibraries = < Library > [];
245246 _addLibrariesWithPaths (
246247 contextLibraries,
247- contextPathList ,
248+ contextPaths ,
248249 excludingLibraryOfPath: path,
249250 );
250251
@@ -291,18 +292,15 @@ class DeclarationsContext {
291292 }
292293
293294 void _addContextFile (String path) {
294- if (! _contextPathList.contains (path)) {
295- _contextPathList.add (path);
296- }
295+ _contextPathSet.add (path);
297296 }
298297
299298 /// Add known libraries, other then in the context itself, or the SDK.
300299 void _addKnownLibraries (List <Library > libraries) {
301- var contextPathSet = _contextPathList.toSet ();
302300 var sdkPathSet = _sdkLibraryPathList.toSet ();
303301
304302 for (var path in _knownPathList) {
305- if (contextPathSet .contains (path) || sdkPathSet.contains (path)) {
303+ if (_contextPathSet .contains (path) || sdkPathSet.contains (path)) {
306304 continue ;
307305 }
308306
@@ -316,12 +314,12 @@ class DeclarationsContext {
316314 }
317315 }
318316
319- void _addLibrariesWithPaths (List <Library > libraries, List <String > pathList ,
317+ void _addLibrariesWithPaths (List <Library > libraries, Iterable <String > paths ,
320318 {String ? excludingLibraryOfPath}) {
321319 var excludedFile = _tracker._pathToFile[excludingLibraryOfPath];
322320 var excludedLibraryPath = (excludedFile? .library ?? excludedFile)? .path;
323321
324- for (var path in pathList ) {
322+ for (var path in paths ) {
325323 if (path == excludedLibraryPath) continue ;
326324
327325 var file = _tracker._pathToFile[path];
@@ -415,7 +413,7 @@ class DeclarationsContext {
415413 void _scheduleContextFiles () {
416414 var contextFiles = _analysisContext.contextRoot.analyzedFiles ();
417415 for (var path in contextFiles) {
418- _contextPathList .add (path);
416+ _contextPathSet .add (path);
419417 _tracker._addFile (this , path);
420418 }
421419 }
0 commit comments