| ... | @@ -277,14 +277,13 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type | ... | @@ -277,14 +277,13 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type |
| 277 | /// The empty slot is filled from the end of the list. | 277 | /// The empty slot is filled from the end of the list. |
| 278 | /// This operation is O(1). | 278 | /// This operation is O(1). |
| 279 | /// This may not preserve item order. Use `orderedRemove` if you need to preserve order. | 279 | /// This may not preserve item order. Use `orderedRemove` if you need to preserve order. |
| 280 | /// Asserts that the list is not empty. | | |
| 281 | /// Asserts that the index is in bounds. | 280 | /// Asserts that the index is in bounds. |
| 282 | pub fn swapRemove(self: *Self, i: usize) T { | 281 | pub fn swapRemove(self: *Self, i: usize) T { |
| 283 | if (self.items.len - 1 == i) return self.pop().?; | 282 | const val = self.items[i]; |
| 284 | | 283 | self.items[i] = self.items[self.items.len - 1]; |
| 285 | const old_item = self.items[i]; | 284 | self.items[self.items.len - 1] = undefined; |
| 286 | self.items[i] = self.pop().?; | 285 | self.items.len -= 1; |
| 287 | return old_item; | 286 | return val; |
| 288 | } | 287 | } |
| 289 | | 288 | |
| 290 | /// Append the slice of items to the list. Allocates more | 289 | /// Append the slice of items to the list. Allocates more |
| ... | @@ -522,6 +521,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type | ... | @@ -522,6 +521,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type |
| 522 | pub fn pop(self: *Self) ?T { | 521 | pub fn pop(self: *Self) ?T { |
| 523 | if (self.items.len == 0) return null; | 522 | if (self.items.len == 0) return null; |
| 524 | const val = self.items[self.items.len - 1]; | 523 | const val = self.items[self.items.len - 1]; |
| | 524 | self.items[self.items.len - 1] = undefined; |
| 525 | self.items.len -= 1; | 525 | self.items.len -= 1; |
| 526 | return val; | 526 | return val; |
| 527 | } | 527 | } |
| ... | @@ -544,8 +544,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type | ... | @@ -544,8 +544,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type |
| 544 | /// Returns the last element from the list. | 544 | /// Returns the last element from the list. |
| 545 | /// Asserts that the list is not empty. | 545 | /// Asserts that the list is not empty. |
| 546 | pub fn getLast(self: Self) T { | 546 | pub fn getLast(self: Self) T { |
| 547 | const val = self.items[self.items.len - 1]; | 547 | return self.items[self.items.len - 1]; |
| 548 | return val; | | |
| 549 | } | 548 | } |
| 550 | | 549 | |
| 551 | /// Returns the last element from the list, or `null` if list is empty. | 550 | /// Returns the last element from the list, or `null` if list is empty. |
| ... | @@ -956,14 +955,13 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { | ... | @@ -956,14 +955,13 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 956 | /// The empty slot is filled from the end of the list. | 955 | /// The empty slot is filled from the end of the list. |
| 957 | /// Invalidates pointers to last element. | 956 | /// Invalidates pointers to last element. |
| 958 | /// This operation is O(1). | 957 | /// This operation is O(1). |
| 959 | /// Asserts that the list is not empty. | | |
| 960 | /// Asserts that the index is in bounds. | 958 | /// Asserts that the index is in bounds. |
| 961 | pub fn swapRemove(self: *Self, i: usize) T { | 959 | pub fn swapRemove(self: *Self, i: usize) T { |
| 962 | if (self.items.len - 1 == i) return self.pop().?; | 960 | const val = self.items[i]; |
| 963 | | 961 | self.items[i] = self.items[self.items.len - 1]; |
| 964 | const old_item = self.items[i]; | 962 | self.items[self.items.len - 1] = undefined; |
| 965 | self.items[i] = self.pop().?; | 963 | self.items.len -= 1; |
| 966 | return old_item; | 964 | return val; |
| 967 | } | 965 | } |
| 968 | | 966 | |
| 969 | /// Append the slice of items to the list. Allocates more | 967 | /// Append the slice of items to the list. Allocates more |
| ... | @@ -1327,6 +1325,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { | ... | @@ -1327,6 +1325,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 1327 | pub fn pop(self: *Self) ?T { | 1325 | pub fn pop(self: *Self) ?T { |
| 1328 | if (self.items.len == 0) return null; | 1326 | if (self.items.len == 0) return null; |
| 1329 | const val = self.items[self.items.len - 1]; | 1327 | const val = self.items[self.items.len - 1]; |
| | 1328 | self.items[self.items.len - 1] = undefined; |
| 1330 | self.items.len -= 1; | 1329 | self.items.len -= 1; |
| 1331 | return val; | 1330 | return val; |
| 1332 | } | 1331 | } |
| ... | @@ -1348,8 +1347,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { | ... | @@ -1348,8 +1347,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 1348 | /// Return the last element from the list. | 1347 | /// Return the last element from the list. |
| 1349 | /// Asserts that the list is not empty. | 1348 | /// Asserts that the list is not empty. |
| 1350 | pub fn getLast(self: Self) T { | 1349 | pub fn getLast(self: Self) T { |
| 1351 | const val = self.items[self.items.len - 1]; | 1350 | return self.items[self.items.len - 1]; |
| 1352 | return val; | | |
| 1353 | } | 1351 | } |
| 1354 | | 1352 | |
| 1355 | /// Return the last element from the list, or | 1353 | /// Return the last element from the list, or |