mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
add llvm refcounting and fix memory leak
This commit is contained in:
parent
7a927b6192
commit
146dff5446
4 changed files with 102 additions and 26 deletions
|
@ -538,11 +538,6 @@ pub fn listSublist(
|
|||
len: usize,
|
||||
dec: Dec,
|
||||
) callconv(.C) RocList {
|
||||
// Alignment is no longer used.
|
||||
// This will never free the original list.
|
||||
// It will either return a seamless slice or an empty list with capacity.
|
||||
_ = alignment;
|
||||
|
||||
const size = list.len();
|
||||
if (len == 0 or start >= size) {
|
||||
if (list.isUnique()) {
|
||||
|
@ -558,6 +553,7 @@ pub fn listSublist(
|
|||
return output;
|
||||
}
|
||||
}
|
||||
list.decref(alignment);
|
||||
return RocList.empty();
|
||||
}
|
||||
|
||||
|
@ -620,9 +616,9 @@ pub fn listDropAt(
|
|||
// For simplicity, do this by calling listSublist.
|
||||
// In the future, we can test if it is faster to manually inline the important parts here.
|
||||
if (drop_index == 0) {
|
||||
return listSublist(list, alignment, element_width, 1, size - 1, dec);
|
||||
} else if (drop_index == size - 1) {
|
||||
return listSublist(list, alignment, element_width, 0, size - 1, dec);
|
||||
return listSublist(list, alignment, element_width, 1, size -| 1, dec);
|
||||
} else if (drop_index == size -| 1) {
|
||||
return listSublist(list, alignment, element_width, 0, size -| 1, dec);
|
||||
}
|
||||
|
||||
if (list.bytes) |source_ptr| {
|
||||
|
|
|
@ -57,6 +57,19 @@ pub const RocStr = extern struct {
|
|||
return result;
|
||||
}
|
||||
|
||||
pub fn fromByteList(list: RocList) RocStr {
|
||||
if (list.isSeamlessSlice()) {
|
||||
// Str doesn't have seamless slices yet.
|
||||
// Need to copy.
|
||||
return RocStr.init(@ptrCast([*]const u8, list.bytes), list.length);
|
||||
}
|
||||
return RocStr{
|
||||
.str_bytes = list.bytes,
|
||||
.str_len = list.length,
|
||||
.str_capacity = list.capacityOrRefPtr, // This is guaranteed to be a proper capcity.
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fromSlice(slice: []const u8) RocStr {
|
||||
return RocStr.init(slice.ptr, slice.len);
|
||||
}
|
||||
|
@ -1800,15 +1813,11 @@ pub fn fromUtf8Range(arg: RocList, start: usize, count: usize, update_mode: Upda
|
|||
if (unicode.utf8ValidateSlice(bytes)) {
|
||||
// the output will be correct. Now we need to clone the input
|
||||
|
||||
// TODO: rework this to properly take advantage fo seamless slices.
|
||||
if (count == arg.len() and count > SMALL_STR_MAX_LENGTH) {
|
||||
const byte_list = arg.makeUniqueExtra(RocStr.alignment, @sizeOf(u8), update_mode);
|
||||
|
||||
// TODO: hangle seamless slice conversion
|
||||
const string = RocStr{
|
||||
.str_bytes = byte_list.bytes,
|
||||
.str_len = byte_list.length,
|
||||
.str_capacity = byte_list.capacityOrRefPtr,
|
||||
};
|
||||
const string = RocStr.fromByteList(byte_list);
|
||||
|
||||
return FromUtf8Result{
|
||||
.is_ok = true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue