fix List.sublist and add some more refcounting tests

This commit is contained in:
Brendan Hansknecht 2024-07-12 20:21:58 -07:00
parent 6e90052000
commit 9052fbd09c
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 88 additions and 10 deletions

View file

@ -535,16 +535,17 @@ pub fn listSublist(
dec: Dec,
) callconv(.C) RocList {
const size = list.len();
if (size == 0 or start_u64 >= @as(u64, @intCast(size))) {
// Decrement the reference counts of all elements.
if (list.bytes) |source_ptr| {
var i: usize = 0;
while (i < size) : (i += 1) {
const element = source_ptr + i * element_width;
dec(element);
}
}
if (size == 0 or len_u64 == 0 or start_u64 >= @as(u64, @intCast(size))) {
if (list.isUnique()) {
// Decrement the reference counts of all elements.
if (list.bytes) |source_ptr| {
var i: usize = 0;
while (i < size) : (i += 1) {
const element = source_ptr + i * element_width;
dec(element);
}
}
var output = list;
output.length = 0;
return output;