mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
use new roc alloc stuff for List.set
This commit is contained in:
parent
91b49ecf98
commit
799e4a3239
2 changed files with 3 additions and 48 deletions
|
@ -989,7 +989,7 @@ inline fn listSetClone(
|
|||
|
||||
const data_bytes = length * element_width;
|
||||
|
||||
var new_bytes = utils.mallocWithRefcount(alignment, data_bytes);
|
||||
var new_bytes = utils.allocateWithRefcount(alignment, data_bytes);
|
||||
|
||||
@memcpy(new_bytes, old_bytes orelse undefined, data_bytes);
|
||||
|
||||
|
@ -1002,7 +1002,8 @@ inline fn listSetClone(
|
|||
// copy in the new element
|
||||
@memcpy(element_at_index, element orelse undefined, element_width);
|
||||
|
||||
// TODO decref the input list!
|
||||
// consume RC token of original
|
||||
utils.decref(alignment, old_bytes, data_bytes);
|
||||
|
||||
//return list;
|
||||
return new_bytes;
|
||||
|
|
|
@ -190,52 +190,6 @@ pub fn allocateWithRefcount(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mallocWithRefcount(
|
||||
alignment: usize,
|
||||
data_bytes: usize,
|
||||
) [*]u8 {
|
||||
comptime const result_in_place = false;
|
||||
|
||||
switch (alignment) {
|
||||
16 => {
|
||||
const length = 2 * @sizeOf(usize) + data_bytes;
|
||||
|
||||
var new_bytes: [*]align(16) u8 = @ptrCast([*]u8, @alignCast(16, std.c.malloc(length)));
|
||||
|
||||
var as_usize_array = @ptrCast([*]usize, new_bytes);
|
||||
if (result_in_place) {
|
||||
as_usize_array[0] = 0;
|
||||
as_usize_array[1] = @intCast(usize, number_of_slots);
|
||||
} else {
|
||||
as_usize_array[0] = 0;
|
||||
as_usize_array[1] = REFCOUNT_ONE;
|
||||
}
|
||||
|
||||
var as_u8_array = @ptrCast([*]u8, new_bytes);
|
||||
const first_slot = as_u8_array + 2 * @sizeOf(usize);
|
||||
|
||||
return first_slot;
|
||||
},
|
||||
else => {
|
||||
const length = @sizeOf(usize) + data_bytes;
|
||||
|
||||
var new_bytes: [*]align(8) u8 = @ptrCast([*]u8, @alignCast(8, std.c.malloc(length)));
|
||||
|
||||
var as_usize_array = @ptrCast([*]isize, new_bytes);
|
||||
if (result_in_place) {
|
||||
as_usize_array[0] = @intCast(isize, number_of_slots);
|
||||
} else {
|
||||
as_usize_array[0] = REFCOUNT_ONE_ISIZE;
|
||||
}
|
||||
|
||||
var as_u8_array = @ptrCast([*]u8, new_bytes);
|
||||
const first_slot = as_u8_array + @sizeOf(usize);
|
||||
|
||||
return first_slot;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unsafeReallocate(
|
||||
source_ptr: [*]u8,
|
||||
alignment: usize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue