mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 11:22:19 +00:00
use copyBackwards when copying overlapping items in non-unique.unique concat
`mem.copy` requires that `dest` has start index `<= src`, but in our case, `dest` has start index `>= src`. For this, `copyBackwards` should be used. See https://github.com/ziglang/zig/blob/master/lib/std/mem.zig#L195-L222. Closes #4697
This commit is contained in:
parent
a549176886
commit
4df83d67ea
1 changed files with 2 additions and 2 deletions
|
@ -772,7 +772,7 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
|
|||
// This first call must use mem.copy because the slices might overlap.
|
||||
const byte_count_a = list_a.len() * element_width;
|
||||
const byte_count_b = list_b.len() * element_width;
|
||||
mem.copy(u8, source_b[byte_count_a .. byte_count_a + byte_count_b], source_b[0..byte_count_b]);
|
||||
mem.copyBackwards(u8, source_b[byte_count_a .. byte_count_a + byte_count_b], source_b[0..byte_count_b]);
|
||||
@memcpy(source_b, source_a, byte_count_a);
|
||||
|
||||
// decrement list a.
|
||||
|
@ -869,7 +869,7 @@ test "listConcat: non-unique with unique overlapping" {
|
|||
defer unique.deinit(u8);
|
||||
|
||||
var concatted = listConcat(nonUnique, unique, 1, 1);
|
||||
var wanted = RocList.fromSlice(u8, ([_]u8{ 1, 2, 2, 2 })[0..]);
|
||||
var wanted = RocList.fromSlice(u8, ([_]u8{ 1, 2, 3, 4 })[0..]);
|
||||
defer wanted.deinit(u8);
|
||||
|
||||
try expect(concatted.eql(wanted));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue