Skip to content

Commit 57c3f53

Browse files
fishythefishCommit Queue
authored andcommitted
[dart2js] Add properties to EnumSetDomain to simplify handling offsets.
Change-Id: I4719bf415d7b29c290d59e46c4eaf2977f3650b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399120 Reviewed-by: Nate Biggs <[email protected]>
1 parent c846765 commit 57c3f53

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pkg/compiler/lib/src/universe/side_effects.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ enum SideEffectsFlag {
1515
staticProperty,
1616
}
1717

18-
final _changes = EnumSetDomain<SideEffectsFlag>(0);
19-
final _depends = EnumSetDomain<SideEffectsFlag>(SideEffectsFlag.values.length);
18+
final _changes = EnumSetDomain<SideEffectsFlag>(0, SideEffectsFlag.values);
19+
final _depends =
20+
EnumSetDomain<SideEffectsFlag>(_changes.nextOffset, SideEffectsFlag.values);
2021

2122
class SideEffects {
2223
/// Tag used for identifying serialized [SideEffects] objects in a debugging
@@ -25,9 +26,9 @@ class SideEffects {
2526

2627
Bitset _flags = Bitset.empty();
2728

28-
static final Bitset allChanges = _changes.allValues(SideEffectsFlag.values);
29+
static final Bitset allChanges = _changes.allValues;
2930

30-
static final Bitset allDepends = _depends.allValues(SideEffectsFlag.values);
31+
static final Bitset allDepends = _depends.allValues;
3132

3233
SideEffects() {
3334
setAllSideEffects();

pkg/compiler/lib/src/util/enumset.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,15 @@ class EnumSetDomain<E extends Enum> {
136136
/// is equivalent to using an [EnumSet] directly.
137137
final int offset;
138138

139-
const EnumSetDomain(this.offset);
139+
final Iterable<E> values;
140+
141+
EnumSetDomain(this.offset, this.values);
142+
143+
/// When composing [EnumSetDomain]s, the [offset] to use for the next domain.
144+
int get nextOffset => offset + values.length;
140145

141146
/// Returns a bitset containing all enum values in [E].
142-
/// [values] is intended to be the `values` property of the enum class.
143-
Bitset allValues(Iterable<E> values) =>
144-
Bitset(((1 << values.length) - 1) << offset);
147+
Bitset get allValues => Bitset(((1 << values.length) - 1) << offset);
145148

146149
/// Returns a singleton bitset containing [value].
147150
Bitset fromValue(E value) => value.mask(offset);

0 commit comments

Comments
 (0)