Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/std/array_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,12 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type
/// The empty slot is filled from the end of the list.
/// This operation is O(1).
/// This may not preserve item order. Use `orderedRemove` if you need to preserve order.
/// Asserts that the list is not empty.
/// Asserts that the index is in bounds.
pub fn swapRemove(self: *Self, i: usize) T {
if (self.items.len - 1 == i) return self.pop().?;

const old_item = self.items[i];
self.items[i] = self.pop().?;
return old_item;
const item = self.items[i];
self.items[i] = self.getLast();
self.items.len -= 1;
return item;
}

/// Append the slice of items to the list. Allocates more
Expand Down Expand Up @@ -956,14 +954,12 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
/// The empty slot is filled from the end of the list.
/// Invalidates pointers to last element.
/// This operation is O(1).
/// Asserts that the list is not empty.
/// Asserts that the index is in bounds.
pub fn swapRemove(self: *Self, i: usize) T {
if (self.items.len - 1 == i) return self.pop().?;

const old_item = self.items[i];
self.items[i] = self.pop().?;
return old_item;
const item = self.items[i];
self.items[i] = self.getLast();
self.items.len -= 1;
return item;
}

/// Append the slice of items to the list. Allocates more
Expand Down