@@ -229,39 +229,18 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
229
229
it .removed_index = null ;
230
230
}
231
231
232
- //
233
- // NOTE: inlining these removal routines is important.
234
- // It gains ~5% in debug mode, and ~8% in release-safe; within 1% of the performance of ArrayList.swapRemove/orderedRemove.
235
- //
236
- // Also note that you'd think that just checking for the index==0 in the removal routines would be
237
- // good for making it illegal if next has not been called yet.
238
- // But no, it is slower to do this for release-safe, and debug modes.
239
- //
240
-
241
- pub inline fn swapRemove (it : * Iterator ) T {
242
- const cursor = it .cursor orelse @panic ("must call next at least once" );
243
- if (it .removed_index == null or
244
- it .removed_index .? != cursor
245
- ) {
246
- it .removed_index = cursor ;
247
- return it .list .swapRemove (cursor );
248
- } else switch (builtin .mode ) {
249
- .ReleaseFast = > unreachable ,
250
- else = > @panic ("removed element more than once" ),
251
- }
232
+ pub fn swapRemove (it : * Iterator ) T {
233
+ var cursor = it .cursor .? ; // must call .next() at least once
234
+ if (it .removed_index ) | ri | assert (ri != cursor ); // removed the same element more than once
235
+ it .removed_index = cursor ;
236
+ return it .list .swapRemove (cursor );
252
237
}
253
238
254
- pub inline fn orderedRemove (it : * Iterator ) T {
255
- const cursor = it .cursor orelse @panic ("must call next at least once" );
256
- if (it .removed_index == null or
257
- it .removed_index .? != cursor
258
- ) {
259
- it .removed_index = cursor ;
260
- return it .list .orderedRemove (cursor );
261
- } else switch (builtin .mode ) {
262
- .ReleaseFast = > unreachable ,
263
- else = > @panic ("removed element more than once" ),
264
- }
239
+ pub fn orderedRemove (it : * Iterator ) T {
240
+ var cursor = it .cursor .? ; // must call .next() at least once
241
+ if (it .removed_index ) | ri | assert (ri != cursor ); // removed the same element more than once
242
+ it .removed_index = cursor ;
243
+ return it .list .orderedRemove (cursor );
265
244
}
266
245
};
267
246
0 commit comments