cache the source lines when running analyze (#3436)
This commit is contained in:
@@ -367,6 +367,8 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
|
||||
Set<String> changedFiles = new Set<String>(); // files about which we've complained that they changed
|
||||
|
||||
_SourceCache cache = new _SourceCache(10);
|
||||
|
||||
int membersMissingDocumentation = 0;
|
||||
List<String> errorLines = output.toString().split('\n');
|
||||
for (String errorLine in errorLines) {
|
||||
@@ -380,7 +382,7 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
int colNumber = int.parse(groups[5]);
|
||||
try {
|
||||
File source = new File(filename);
|
||||
List<String> sourceLines = source.readAsLinesSync();
|
||||
List<String> sourceLines = cache.getSourceFor(source);
|
||||
if (lineNumber > sourceLines.length)
|
||||
throw new FileChanged();
|
||||
String sourceLine = sourceLines[lineNumber-1];
|
||||
@@ -801,3 +803,20 @@ class AnalysisError implements Comparable<AnalysisError> {
|
||||
return '${severity.toLowerCase().padLeft(7)} $sep $message $sep $relativePath:$startLine:$startColumn';
|
||||
}
|
||||
}
|
||||
|
||||
class _SourceCache {
|
||||
_SourceCache(this.cacheSize);
|
||||
|
||||
final int cacheSize;
|
||||
final Map<String, List<String>> _lines = new LinkedHashMap<String, List<String>>();
|
||||
|
||||
List<String> getSourceFor(File file) {
|
||||
if (!_lines.containsKey(file.path)) {
|
||||
if (_lines.length >= cacheSize)
|
||||
_lines.remove(_lines.keys.first);
|
||||
_lines[file.path] = file.readAsLinesSync();
|
||||
}
|
||||
|
||||
return _lines[file.path];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user