mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge pull request #3503 from rtfeldman/string-memory-problems
String memory problems
This commit is contained in:
commit
77afe0c1f1
3 changed files with 22 additions and 4 deletions
|
@ -1674,16 +1674,31 @@ pub fn fromUtf8Range(arg: RocList, start: usize, count: usize, update_mode: Upda
|
||||||
.problem_code = Utf8ByteProblem.InvalidStartByte,
|
.problem_code = Utf8ByteProblem.InvalidStartByte,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// turn the bytes into a small string
|
||||||
|
const string = RocStr.init(@ptrCast([*]const u8, bytes), count);
|
||||||
|
|
||||||
|
// decref the list
|
||||||
|
utils.decref(arg.bytes, arg.len(), 1);
|
||||||
|
|
||||||
return FromUtf8Result{
|
return FromUtf8Result{
|
||||||
.is_ok = true,
|
.is_ok = true,
|
||||||
.string = RocStr.init(@ptrCast([*]const u8, bytes), count),
|
.string = string,
|
||||||
.byte_index = 0,
|
.byte_index = 0,
|
||||||
.problem_code = Utf8ByteProblem.InvalidStartByte,
|
.problem_code = Utf8ByteProblem.InvalidStartByte,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const temp = errorToProblem(@ptrCast([*]u8, arg.bytes), arg.length);
|
const temp = errorToProblem(@ptrCast([*]u8, arg.bytes), arg.length);
|
||||||
return FromUtf8Result{ .is_ok = false, .string = RocStr.empty(), .byte_index = temp.index, .problem_code = temp.problem };
|
|
||||||
|
// decref the list
|
||||||
|
utils.decref(arg.bytes, arg.len(), 1);
|
||||||
|
|
||||||
|
return FromUtf8Result{
|
||||||
|
.is_ok = false,
|
||||||
|
.string = RocStr.empty(),
|
||||||
|
.byte_index = temp.index,
|
||||||
|
.problem_code = temp.problem,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -820,7 +820,10 @@ findIndex = \list, matcher ->
|
||||||
## Some languages have a function called **`slice`** which works similarly to this.
|
## Some languages have a function called **`slice`** which works similarly to this.
|
||||||
sublist : List elem, { start : Nat, len : Nat } -> List elem
|
sublist : List elem, { start : Nat, len : Nat } -> List elem
|
||||||
sublist = \list, config ->
|
sublist = \list, config ->
|
||||||
sublistLowlevel list config.start config.len
|
if config.len == 0 then
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
sublistLowlevel list config.start config.len
|
||||||
|
|
||||||
sublistLowlevel : List elem, Nat, Nat -> List elem
|
sublistLowlevel : List elem, Nat, Nat -> List elem
|
||||||
|
|
||||||
|
|
|
@ -935,7 +935,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
||||||
NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||||
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[borrowed, borrowed]),
|
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[borrowed, borrowed]),
|
||||||
StrStartsWithScalar => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
StrStartsWithScalar => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||||
StrFromUtf8Range => arena.alloc_slice_copy(&[borrowed, irrelevant, irrelevant]),
|
StrFromUtf8Range => arena.alloc_slice_copy(&[owned, irrelevant, irrelevant]),
|
||||||
StrToUtf8 => arena.alloc_slice_copy(&[owned]),
|
StrToUtf8 => arena.alloc_slice_copy(&[owned]),
|
||||||
StrRepeat => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
StrRepeat => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||||
StrFromInt | StrFromFloat => arena.alloc_slice_copy(&[irrelevant]),
|
StrFromInt | StrFromFloat => arena.alloc_slice_copy(&[irrelevant]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue