@@ -6,39 +6,28 @@ library universe.side_effects;
66
77import '../elements/entities.dart' ;
88import '../serialization/serialization.dart' ;
9+ import '../util/bitset.dart' ;
910import '../util/enumset.dart' ;
1011
11- typedef SideEffectsFlags = EnumSet <SideEffectsFlag >;
12-
1312enum SideEffectsFlag {
14- // Changes flags.
15- changesIndex,
16- changesInstanceProperty,
17- changesStaticProperty,
18-
19- // Depends flags (one for each changes flag).
20- dependsOnIndexStore,
21- dependsOnInstancePropertyStore,
22- dependsOnStaticPropertyStore,
23- ;
24-
25- static final int _changesCount = dependsOnIndexStore.index;
26- static final int _dependsCount = values.length - _changesCount;
13+ index_,
14+ instanceProperty,
15+ staticProperty,
2716}
2817
18+ final _changes = EnumSetDomain <SideEffectsFlag >(0 );
19+ final _depends = EnumSetDomain <SideEffectsFlag >(SideEffectsFlag .values.length);
20+
2921class SideEffects {
3022 /// Tag used for identifying serialized [SideEffects] objects in a debugging
3123 /// data stream.
3224 static const String tag = 'side-effects' ;
3325
34- EnumSet < SideEffectsFlag > _flags = EnumSet .empty ();
26+ Bitset _flags = Bitset .empty ();
3527
36- static final EnumSet <SideEffectsFlag > allChanges =
37- EnumSet .fromRawBits ((1 << SideEffectsFlag ._changesCount) - 1 );
28+ static final Bitset allChanges = _changes.allValues (SideEffectsFlag .values);
3829
39- static final EnumSet <SideEffectsFlag > allDepends = EnumSet .fromRawBits (
40- ((1 << SideEffectsFlag ._dependsCount) - 1 ) <<
41- SideEffectsFlag ._changesCount);
30+ static final Bitset allDepends = _depends.allValues (SideEffectsFlag .values);
4231
4332 SideEffects () {
4433 setAllSideEffects ();
@@ -50,20 +39,20 @@ class SideEffects {
5039 clearAllSideEffects ();
5140 }
5241
53- SideEffects .fromFlags ( this . _flags);
42+ SideEffects ._fromBits ( int bits) : _flags = Bitset (bits );
5443
5544 /// Deserializes a [SideEffects] object from [source] .
5645 factory SideEffects .readFromDataSource (DataSourceReader source) {
5746 source.begin (tag);
58- int flags = source.readInt ();
47+ int bits = source.readInt ();
5948 source.end (tag);
60- return SideEffects .fromFlags ( EnumSet . fromRawBits (flags) );
49+ return SideEffects ._fromBits (bits );
6150 }
6251
6352 /// Serializes this [SideEffects] to [sink] .
6453 void writeToDataSink (DataSinkWriter sink) {
6554 sink.begin (tag);
66- sink.writeInt (_flags.mask. bits);
55+ sink.writeInt (_flags.bits);
6756 sink.end (tag);
6857 }
6958
@@ -74,24 +63,37 @@ class SideEffects {
7463 @override
7564 int get hashCode => throw UnsupportedError ('SideEffects.hashCode' );
7665
77- bool _getFlag (SideEffectsFlag flag) => _flags.contains (flag);
66+ bool _getChangesFlag (SideEffectsFlag flag) => _changes.contains (_flags, flag);
67+
68+ bool _getDependsFlag (SideEffectsFlag flag) => _depends.contains (_flags, flag);
69+
70+ bool _setChangesFlag (SideEffectsFlag flag) {
71+ final before = _flags;
72+ _flags = _changes.add (_flags, flag);
73+ return before != _flags;
74+ }
75+
76+ bool _setDependsFlag (SideEffectsFlag flag) {
77+ final before = _flags;
78+ _flags = _depends.add (_flags, flag);
79+ return before != _flags;
80+ }
7881
79- bool _setFlag (SideEffectsFlag flag) {
82+ bool _clearChangesFlag (SideEffectsFlag flag) {
8083 final before = _flags;
81- _flags += flag;
84+ _flags = _changes. remove (_flags, flag) ;
8285 return before != _flags;
8386 }
8487
85- bool _clearFlag (SideEffectsFlag flag) {
88+ bool _clearDependsFlag (SideEffectsFlag flag) {
8689 final before = _flags;
87- _flags -= flag;
90+ _flags = _depends. remove (_flags, flag) ;
8891 return before != _flags;
8992 }
9093
91- EnumSet < SideEffectsFlag > getChangesFlags () => _flags.intersection (allChanges);
94+ Bitset getChangesFlags () => _flags.intersection (allChanges);
9295
93- EnumSet <SideEffectsFlag > getDependsOnFlags () =>
94- _flags.intersection (allDepends);
96+ Bitset getDependsOnFlags () => _flags.intersection (allDepends);
9597
9698 bool hasSideEffects () => getChangesFlags () != 0 ;
9799 bool dependsOnSomething () => getDependsOnFlags () != 0 ;
@@ -121,61 +123,57 @@ class SideEffects {
121123 }
122124
123125 bool dependsOnStaticPropertyStore () =>
124- _getFlag (SideEffectsFlag .dependsOnStaticPropertyStore );
126+ _getDependsFlag (SideEffectsFlag .staticProperty );
125127
126128 bool setDependsOnStaticPropertyStore () =>
127- _setFlag (SideEffectsFlag .dependsOnStaticPropertyStore );
129+ _setDependsFlag (SideEffectsFlag .staticProperty );
128130
129131 bool clearDependsOnStaticPropertyStore () =>
130- _clearFlag (SideEffectsFlag .dependsOnStaticPropertyStore );
132+ _clearDependsFlag (SideEffectsFlag .staticProperty );
131133
132134 bool setChangesStaticProperty () =>
133- _setFlag (SideEffectsFlag .changesStaticProperty );
135+ _setChangesFlag (SideEffectsFlag .staticProperty );
134136
135137 bool clearChangesStaticProperty () =>
136- _clearFlag (SideEffectsFlag .changesStaticProperty );
138+ _clearChangesFlag (SideEffectsFlag .staticProperty );
137139
138140 bool changesStaticProperty () =>
139- _getFlag (SideEffectsFlag .changesStaticProperty );
141+ _getChangesFlag (SideEffectsFlag .staticProperty );
140142
141- bool dependsOnIndexStore () => _getFlag (SideEffectsFlag .dependsOnIndexStore );
143+ bool dependsOnIndexStore () => _getDependsFlag (SideEffectsFlag .index_ );
142144
143- bool setDependsOnIndexStore () =>
144- _setFlag (SideEffectsFlag .dependsOnIndexStore);
145+ bool setDependsOnIndexStore () => _setDependsFlag (SideEffectsFlag .index_);
145146
146- bool clearDependsOnIndexStore () =>
147- _clearFlag (SideEffectsFlag .dependsOnIndexStore);
147+ bool clearDependsOnIndexStore () => _clearDependsFlag (SideEffectsFlag .index_);
148148
149- bool setChangesIndex () => _setFlag (SideEffectsFlag .changesIndex );
149+ bool setChangesIndex () => _setChangesFlag (SideEffectsFlag .index_ );
150150
151- bool clearChangesIndex () => _clearFlag (SideEffectsFlag .changesIndex );
151+ bool clearChangesIndex () => _clearChangesFlag (SideEffectsFlag .index_ );
152152
153- bool changesIndex () => _getFlag (SideEffectsFlag .changesIndex );
153+ bool changesIndex () => _getChangesFlag (SideEffectsFlag .index_ );
154154
155155 bool dependsOnInstancePropertyStore () =>
156- _getFlag (SideEffectsFlag .dependsOnInstancePropertyStore );
156+ _getDependsFlag (SideEffectsFlag .instanceProperty );
157157
158158 bool setDependsOnInstancePropertyStore () =>
159- _setFlag (SideEffectsFlag .dependsOnInstancePropertyStore );
159+ _setDependsFlag (SideEffectsFlag .instanceProperty );
160160
161161 bool clearDependsOnInstancePropertyStore () =>
162- _setFlag (SideEffectsFlag .dependsOnInstancePropertyStore );
162+ _setDependsFlag (SideEffectsFlag .instanceProperty );
163163
164164 bool setChangesInstanceProperty () =>
165- _setFlag (SideEffectsFlag .changesInstanceProperty );
165+ _setChangesFlag (SideEffectsFlag .instanceProperty );
166166
167167 bool clearChangesInstanceProperty () =>
168- _clearFlag (SideEffectsFlag .changesInstanceProperty );
168+ _clearChangesFlag (SideEffectsFlag .instanceProperty );
169169
170170 bool changesInstanceProperty () =>
171- _getFlag (SideEffectsFlag .changesInstanceProperty );
171+ _getChangesFlag (SideEffectsFlag .instanceProperty );
172172
173- static EnumSet <SideEffectsFlag > computeDependsOnFlags (
174- EnumSet <SideEffectsFlag > flags) =>
175- EnumSet .fromRawBits (flags.mask.bits << SideEffectsFlag ._changesCount);
173+ static Bitset computeDependsOnFlags (Bitset flags) =>
174+ Bitset (flags.bits << SideEffectsFlag .values.length);
176175
177- bool dependsOn (EnumSet <SideEffectsFlag > dependsFlags) =>
178- _flags.intersects (dependsFlags);
176+ bool dependsOn (Bitset dependsFlags) => _flags.intersects (dependsFlags);
179177
180178 bool add (SideEffects other) {
181179 final before = _flags;
0 commit comments