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

Unified Diff: pkg/kernel/lib/class_hierarchy.dart

Issue 2627723003: Improvements to the kernel tree shaker. (Closed)
Patch Set: Revert+Unrevert, and update status files Created 3 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 | « no previous file | pkg/kernel/lib/core_types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/class_hierarchy.dart
diff --git a/pkg/kernel/lib/class_hierarchy.dart b/pkg/kernel/lib/class_hierarchy.dart
index 6771cc4560220bc7865d7eaea80b2189e215927f..40bc6e7972d429d37d03430eef3af6082b8cfc0b 100644
--- a/pkg/kernel/lib/class_hierarchy.dart
+++ b/pkg/kernel/lib/class_hierarchy.dart
@@ -234,11 +234,18 @@ class ClassHierarchy {
/// True if the program contains another class that is a subtype of given one.
bool hasProperSubtypes(Class class_) {
- var info = _infoFor[class_];
- var subtypes = info.subtypeIntervalList;
- return !(subtypes.length == 2 &&
- subtypes[0] == info.topDownIndex &&
- subtypes[1] == info.topDownIndex + 1);
+ // If there are no subtypes then the subtype set contains the class itself.
+ return !getSubtypesOf(class_).isSingleton;
+ }
+
+ /// Returns the subtypes of [class_] as an interval list.
+ ClassSet getSubtypesOf(Class class_) {
+ return new ClassSet(this, _infoFor[class_].subtypeIntervalList);
+ }
+
+ /// Returns the subclasses of [class_] as an interval list.
+ ClassSet getSubclassesOf(Class class_) {
+ return new ClassSet(this, _infoFor[class_].subclassIntervalList);
}
ClassHierarchy._internal(Program program, int numberOfClasses)
@@ -864,3 +871,32 @@ class _ClassInfo {
_ClassInfo(this.classNode);
}
+
+/// An immutable set of classes, internally represented as an interval list.
+class ClassSet {
+ final ClassHierarchy _hierarchy;
+ final Uint32List _intervalList;
+
+ ClassSet(this._hierarchy, this._intervalList);
+
+ bool get isEmpty => _intervalList.isEmpty;
+
+ bool get isSingleton {
+ var list = _intervalList;
+ return list.length == 2 && list[0] + 1 == list[1];
+ }
+
+ bool contains(Class class_) {
+ return _intervalListContains(
+ _intervalList, _hierarchy._infoFor[class_].topDownIndex);
+ }
+
+ ClassSet union(ClassSet other) {
+ assert(_hierarchy == other._hierarchy);
+ if (identical(_intervalList, other._intervalList)) return this;
+ _IntervalListBuilder builder = new _IntervalListBuilder();
+ builder.addIntervalList(_intervalList);
+ builder.addIntervalList(other._intervalList);
+ return new ClassSet(_hierarchy, builder.buildIntervalList());
+ }
+}
« no previous file with comments | « no previous file | pkg/kernel/lib/core_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698