@@ -184,7 +184,7 @@ public override DValue<RecordValue> Last(bool mutationCopy = false)
184
184
public override async Task < DValue < BooleanValue > > RemoveAsync ( IEnumerable < FormulaValue > recordsToRemove , bool all , CancellationToken cancellationToken )
185
185
{
186
186
var ret = false ;
187
- var markedToDeletion = new HashSet < T > ( ) ;
187
+ var markedToDeletionIndexes = new HashSet < int > ( ) ;
188
188
var errors = new List < ExpressionError > ( ) ;
189
189
190
190
cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -194,26 +194,29 @@ public override async Task<DValue<BooleanValue>> RemoveAsync(IEnumerable<Formula
194
194
return await base . RemoveAsync ( recordsToRemove , all , cancellationToken ) . ConfigureAwait ( false ) ;
195
195
}
196
196
197
+ var rowsArray = _enumerator . ToArray ( ) ;
198
+
197
199
foreach ( RecordValue recordToRemove in recordsToRemove )
198
200
{
199
201
var found = false ;
200
202
201
- foreach ( T item in _enumerator )
203
+ for ( int i = 0 ; i < rowsArray . Length ; i ++ )
202
204
{
203
205
cancellationToken . ThrowIfCancellationRequested ( ) ;
204
206
207
+ var item = rowsArray [ i ] ;
205
208
DValue < RecordValue > dRecord = Marshal ( item ) ;
206
209
207
210
if ( await MatchesAsync ( dRecord . Value , recordToRemove , cancellationToken ) . ConfigureAwait ( false ) )
208
211
{
209
- if ( markedToDeletion . Contains ( item ) )
212
+ if ( markedToDeletionIndexes . Contains ( i ) )
210
213
{
211
214
continue ;
212
215
}
213
216
else
214
217
{
215
218
found = true ;
216
- markedToDeletion . Add ( item ) ;
219
+ markedToDeletionIndexes . Add ( i ) ;
217
220
}
218
221
219
222
if ( ! all )
@@ -230,9 +233,9 @@ public override async Task<DValue<BooleanValue>> RemoveAsync(IEnumerable<Formula
230
233
}
231
234
}
232
235
233
- foreach ( var delete in markedToDeletion )
236
+ foreach ( var index in markedToDeletionIndexes )
234
237
{
235
- _sourceList . Remove ( delete ) ;
238
+ _sourceList . Remove ( rowsArray [ index ] ) ;
236
239
ret = true ;
237
240
}
238
241
0 commit comments