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

Unified Diff: lib/src/rule/rule.dart

Issue 1418483008: Optimize splitting lines with many rules. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 1 month 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
« lib/src/line_splitting/solve_state.dart ('K') | « lib/src/rule/argument.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/rule/rule.dart
diff --git a/lib/src/rule/rule.dart b/lib/src/rule/rule.dart
index 4afcc54895973c68059f7feed206ca80888ce0f6..e43d21ba2f00cc10b197f2a0d9f5c971f99fb54d 100644
--- a/lib/src/rule/rule.dart
+++ b/lib/src/rule/rule.dart
@@ -41,7 +41,6 @@ abstract class Rule extends FastHash {
///
/// This contains all direct as well as transitive relationships. If A
/// contains B which contains C, C's outerRules contains both B and A.
- Iterable<Rule> get outerRules => _outerRules;
final Set<Rule> _outerRules = new Set<Rule>();
/// Adds [inner] as an inner rule of this rule if it cares about inner rules.
@@ -78,8 +77,42 @@ abstract class Rule extends FastHash {
return null;
}
+ /// A protected method for subclasses to add the rules that they constrain
+ /// to [rules].
+ ///
+ /// Called by [Rule] the first time [constrainedRules] is accessed.
+ void addConstrainedRules(Set<Rule> rules) {}
+
+ /// Discards constraints on any rule that doesn't have an index.
+ ///
+ /// This is called by [LineSplitter] after it has indexed all of the in-use
+ /// rules. A rule may end up with a constraint on a rule that's no longer
+ /// used by any chunk. This can happen if the rule gets hardened, or if it
+ /// simply never got used by a chunk. For example, a rule for splitting an
+ /// empty list of metadata annotations.
+ ///
+ /// This removes all of those.
+ void forgetUnusedRules() {
+ _outerRules.retainWhere((rule) => rule.index != null);
+
+ // Clear the cached ones too.
+ _constrainedRules = null;
+ _allConstrainedRules = null;
+ }
+
/// The other [Rule]s that this rule places immediate constraints on.
- Iterable<Rule> get constrainedRules => _outerRules;
+ Set<Rule> get constrainedRules {
+ // Lazy initialize this on first use. Note: Assumes this is only called
+ // after the chunks have been written and any constraints have been wired
+ // up.
+ if (_constrainedRules == null) {
+ _constrainedRules = _outerRules.toSet();
+ addConstrainedRules(_constrainedRules);
+ }
+
+ return _constrainedRules;
+ }
+ Set<Rule> _constrainedRules;
/// The transitive closure of all of the rules this rule places constraints
/// on, directly or indirectly, including itself.
« lib/src/line_splitting/solve_state.dart ('K') | « lib/src/rule/argument.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698