Commit 731c5903 authored by Devon Carew's avatar Devon Carew

cache the source lines when running analyze (#3436)

parent 112f2cc3
...@@ -367,6 +367,8 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -367,6 +367,8 @@ class AnalyzeCommand extends FlutterCommand {
Set<String> changedFiles = new Set<String>(); // files about which we've complained that they changed Set<String> changedFiles = new Set<String>(); // files about which we've complained that they changed
_SourceCache cache = new _SourceCache(10);
int membersMissingDocumentation = 0; int membersMissingDocumentation = 0;
List<String> errorLines = output.toString().split('\n'); List<String> errorLines = output.toString().split('\n');
for (String errorLine in errorLines) { for (String errorLine in errorLines) {
...@@ -380,7 +382,7 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -380,7 +382,7 @@ class AnalyzeCommand extends FlutterCommand {
int colNumber = int.parse(groups[5]); int colNumber = int.parse(groups[5]);
try { try {
File source = new File(filename); File source = new File(filename);
List<String> sourceLines = source.readAsLinesSync(); List<String> sourceLines = cache.getSourceFor(source);
if (lineNumber > sourceLines.length) if (lineNumber > sourceLines.length)
throw new FileChanged(); throw new FileChanged();
String sourceLine = sourceLines[lineNumber-1]; String sourceLine = sourceLines[lineNumber-1];
...@@ -801,3 +803,20 @@ class AnalysisError implements Comparable<AnalysisError> { ...@@ -801,3 +803,20 @@ class AnalysisError implements Comparable<AnalysisError> {
return '${severity.toLowerCase().padLeft(7)} $sep $message $sep $relativePath:$startLine:$startColumn'; 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];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment