fix bug where we don't decrement elements if the list is non-unique

This commit is contained in:
Brendan Hansknecht 2023-03-15 23:43:15 -07:00
parent a955a4937c
commit 2a6c82c937
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -606,19 +606,19 @@ pub fn listSublist(
) callconv(.C) RocList {
const size = list.len();
if (len == 0 or start >= 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;
// 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 (list.isUnique()) {
var output = list;
output.length = 0;
return output;
}
list.decref(alignment);
return RocList.empty();
}