Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Unified Diff: lib/src/source_visitor.dart

Issue 1595553004: Better performance on long lists containing comments. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/chunk_builder.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source_visitor.dart
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 529e420a4eff3d0ec548a0a13bc72b4dc1577ca2..48306ac204e605ac066d4be9b40d90a4a3a0d22e 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1880,25 +1880,42 @@ class SourceVisitor implements AstVisitor {
_startLiteralBody(leftBracket);
- // Always use a hard rule to split the elements. The parent chunk of
- // the collection will handle the unsplit case, so this only comes
- // into play when the collection is split.
- var rule = new Rule.hard();
- builder.startRule(rule);
-
// If a collection contains a line comment, we assume it's a big complex
// blob of data with some documented structure. In that case, the user
// probably broke the elements into lines deliberately, so preserve those.
var preserveNewlines = _containsLineComments(elements, rightBracket);
+ var rule;
+ var lineRule;
+ if (preserveNewlines) {
+ // Newlines are significant, so we'll explicitly write those. Elements
+ // on the same line all share an argument-list-like rule that allows
+ // splitting between zero, one, or all of them. This is faster in long
+ // lists than using individual splits after each element.
+ lineRule = new TypeArgumentRule();
+ builder.startLazyRule(lineRule);
+ } else {
+ // Newlines aren't significant, so use a hard rule to split the elements.
+ // The parent chunk of the collection will handle the unsplit case, so
+ // this only comes into play when the collection is split.
+ rule = new Rule.hard();
+ builder.startRule(rule);
+ }
+
for (var element in elements) {
if (element != elements.first) {
if (preserveNewlines) {
+ // See if the next element is on the next line.
if (_endLine(element.beginToken.previous) !=
_startLine(element.beginToken)) {
oneOrTwoNewlines();
+
+ // Start a new rule for the new line.
+ builder.endRule();
+ lineRule = new TypeArgumentRule();
+ builder.startLazyRule(lineRule);
} else {
- soloSplit();
+ lineRule.beforeArgument(split());
}
} else {
builder.split(nest: false, space: true);
« no previous file with comments | « lib/src/chunk_builder.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698