@@ -16,20 +16,19 @@ class SourceCrawlerImpl implements SourceCrawler {
16
16
SourceCrawlerImpl (this .packageRoots);
17
17
18
18
void crawl (String entryPoint, CompilationUnitVisitor visitor) {
19
- List < String > visited = < String > [] ;
20
- List < String > toVisit = < String > [] ;
19
+ final visited = new Set <String >() ;
20
+ final toVisit = new Set <String >() ;
21
21
if (entryPoint.startsWith (PACKAGE_PREFIX )) {
22
22
var path = resolvePackagePath (entryPoint);
23
- if (path == null ) {
24
- throw 'Unable to resolve $entryPoint ' ;
25
- }
23
+ if (path == null ) throw 'Unable to resolve $entryPoint ' ;
26
24
toVisit.add (path);
27
25
} else {
28
26
toVisit.add (entryPoint);
29
27
}
30
28
31
29
while (toVisit.isNotEmpty) {
32
- var currentFile = toVisit.removeAt (0 );
30
+ var currentFile = toVisit.first;
31
+ toVisit.remove (currentFile);
33
32
visited.add (currentFile);
34
33
var file = new File (currentFile);
35
34
// Possible source file doesn't exist. For example if it is generated.
@@ -42,8 +41,8 @@ class SourceCrawlerImpl implements SourceCrawler {
42
41
}
43
42
44
43
void processImports (CompilationUnit cu, String currentDir,
45
- String currentFile, List <String > visited,
46
- List <String > toVisit) {
44
+ String currentFile, Set <String > visited,
45
+ Set <String > toVisit) {
47
46
cu.directives.forEach ((Directive directive) {
48
47
if (directive is ImportDirective ||
49
48
directive is PartDirective ||
@@ -52,10 +51,7 @@ class SourceCrawlerImpl implements SourceCrawler {
52
51
String canonicalFile = canonicalizeImportPath (
53
52
currentDir, currentFile, import.uri.stringValue);
54
53
if (canonicalFile == null ) return ;
55
- if (! visited.contains (canonicalFile) &&
56
- ! toVisit.contains (canonicalFile)) {
57
- toVisit.add (canonicalFile);
58
- }
54
+ if (! visited.contains (canonicalFile)) toVisit.add (canonicalFile);
59
55
}
60
56
});
61
57
}
@@ -64,12 +60,8 @@ class SourceCrawlerImpl implements SourceCrawler {
64
60
String currentFile,
65
61
String uri) {
66
62
// ignore core libraries
67
- if (uri.startsWith ('dart:' )) {
68
- return null ;
69
- }
70
- if (uri.startsWith (PACKAGE_PREFIX )) {
71
- return resolvePackagePath (uri);
72
- }
63
+ if (uri.startsWith ('dart:' )) return null ;
64
+ if (uri.startsWith (PACKAGE_PREFIX )) return resolvePackagePath (uri);
73
65
// relative import.
74
66
if (uri.startsWith ('../' )) {
75
67
while (uri.startsWith ('../' )) {
@@ -83,18 +75,14 @@ class SourceCrawlerImpl implements SourceCrawler {
83
75
String resolvePackagePath (String uri) {
84
76
for (String packageRoot in packageRoots) {
85
77
var resolvedPath = _packageUriResolver (uri, packageRoot);
86
- if (new File (resolvedPath).existsSync ()) {
87
- return resolvedPath;
88
- }
78
+ if (new File (resolvedPath).existsSync ()) return resolvedPath;
89
79
}
90
80
return null ;
91
81
}
92
82
93
83
String _packageUriResolver (String uri, String packageRoot) {
94
84
var packagePath = uri.substring (PACKAGE_PREFIX .length);
95
- if (! packageRoot.endsWith ('/' )) {
96
- packageRoot = packageRoot + '/' ;
97
- }
85
+ if (! packageRoot.endsWith ('/' )) packageRoot = packageRoot + '/' ;
98
86
return packageRoot + packagePath;
99
87
}
100
88
}
0 commit comments