@@ -112,11 +112,17 @@ pub struct StoreDiff {
112
112
/// one addition and (optionally) one deletion (in that order!).
113
113
pub row_id : RowId ,
114
114
115
- /// The [`TimePoint`] associated with that row.
115
+ /// The time data associated with that row.
116
116
///
117
117
/// Since insertions and deletions both work on a row-level basis, this is guaranteed to be the
118
118
/// same value for both the insertion and deletion events (if any).
119
- pub timepoint : TimePoint ,
119
+ ///
120
+ /// This is not a [`TimePoint`] for performance reasons.
121
+ //
122
+ // NOTE: Empirical testing shows that a SmallVec isn't any better in the best case, and can be a
123
+ // significant performant drop at worst.
124
+ // pub times: SmallVec<[(Timeline, TimeInt); 5]>, // "5 timelines ought to be enough for anyone"
125
+ pub times : Vec < ( Timeline , TimeInt ) > ,
120
126
121
127
/// The [`EntityPath`] associated with that row.
122
128
///
@@ -137,7 +143,7 @@ impl StoreDiff {
137
143
Self {
138
144
kind : StoreDiffKind :: Addition ,
139
145
row_id : row_id. into ( ) ,
140
- timepoint : TimePoint :: timeless ( ) ,
146
+ times : Default :: default ( ) ,
141
147
entity_path : entity_path. into ( ) ,
142
148
cells : Default :: default ( ) ,
143
149
}
@@ -148,75 +154,43 @@ impl StoreDiff {
148
154
Self {
149
155
kind : StoreDiffKind :: Deletion ,
150
156
row_id : row_id. into ( ) ,
151
- timepoint : TimePoint :: timeless ( ) ,
157
+ times : Default :: default ( ) ,
152
158
entity_path : entity_path. into ( ) ,
153
159
cells : Default :: default ( ) ,
154
160
}
155
161
}
156
162
157
163
#[ inline]
158
- pub fn at_timepoint ( mut self , timepoint : impl Into < TimePoint > ) -> StoreDiff {
159
- self . timepoint = self . timepoint . union_max ( & timepoint. into ( ) ) ;
164
+ pub fn at_timepoint ( & mut self , timepoint : impl Into < TimePoint > ) -> & mut Self {
165
+ self . times . extend ( timepoint. into ( ) ) ;
160
166
self
161
167
}
162
168
163
169
#[ inline]
164
170
pub fn at_timestamp (
165
- mut self ,
171
+ & mut self ,
166
172
timeline : impl Into < Timeline > ,
167
173
time : impl Into < TimeInt > ,
168
- ) -> StoreDiff {
169
- self . timepoint . insert ( timeline. into ( ) , time. into ( ) ) ;
174
+ ) -> & mut Self {
175
+ self . times . push ( ( timeline. into ( ) , time. into ( ) ) ) ;
170
176
self
171
177
}
172
178
173
179
#[ inline]
174
- pub fn with_cells ( mut self , cells : impl IntoIterator < Item = DataCell > ) -> Self {
180
+ pub fn with_cells ( & mut self , cells : impl IntoIterator < Item = DataCell > ) -> & mut Self {
175
181
self . cells
176
182
. extend ( cells. into_iter ( ) . map ( |cell| ( cell. component_name ( ) , cell) ) ) ;
177
183
self
178
184
}
179
185
180
- /// Returns the union of two [`StoreDiff`]s.
181
- ///
182
- /// They must share the same [`RowId`], [`EntityPath`] and [`StoreDiffKind`].
183
186
#[ inline]
184
- pub fn union ( & self , rhs : & Self ) -> Option < Self > {
185
- let Self {
186
- kind : lhs_kind,
187
- row_id : lhs_row_id,
188
- timepoint : lhs_timepoint,
189
- entity_path : lhs_entity_path,
190
- cells : lhs_cells,
191
- } = self ;
192
- let Self {
193
- kind : rhs_kind,
194
- row_id : rhs_row_id,
195
- timepoint : rhs_timepoint,
196
- entity_path : rhs_entity_path,
197
- cells : rhs_cells,
198
- } = rhs;
199
-
200
- let same_kind = lhs_kind == rhs_kind;
201
- let same_row_id = lhs_row_id == rhs_row_id;
202
- let same_entity_path = lhs_entity_path == rhs_entity_path;
203
-
204
- ( same_kind && same_row_id && same_entity_path) . then ( || Self {
205
- kind : * lhs_kind,
206
- row_id : * lhs_row_id,
207
- timepoint : lhs_timepoint. clone ( ) . union_max ( rhs_timepoint) ,
208
- entity_path : lhs_entity_path. clone ( ) ,
209
- cells : [ lhs_cells. values ( ) , rhs_cells. values ( ) ]
210
- . into_iter ( )
211
- . flatten ( )
212
- . map ( |cell| ( cell. component_name ( ) , cell. clone ( ) ) )
213
- . collect ( ) ,
214
- } )
187
+ pub fn timepoint ( & self ) -> TimePoint {
188
+ self . times . clone ( ) . into_iter ( ) . collect ( )
215
189
}
216
190
217
191
#[ inline]
218
192
pub fn is_timeless ( & self ) -> bool {
219
- self . timepoint . is_timeless ( )
193
+ self . times . is_empty ( )
220
194
}
221
195
222
196
/// `-1` for deletions, `+1` for additions.
@@ -297,7 +271,7 @@ mod tests {
297
271
if event. is_timeless ( ) {
298
272
self . timeless += delta;
299
273
} else {
300
- for ( & timeline, & time) in & event. timepoint {
274
+ for & ( timeline, time) in & event. times {
301
275
* self . timelines . entry ( timeline) . or_default ( ) += delta;
302
276
* self . times . entry ( time) . or_default ( ) += delta;
303
277
}
0 commit comments