mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
make Str.fromUtf8 in-place
This commit is contained in:
parent
9e97a09a87
commit
018348bd83
6 changed files with 49 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
const std = @import("std");
|
||||
const utils = @import("utils.zig");
|
||||
const RocResult = utils.RocResult;
|
||||
const UpdateMode = utils.UpdateMode;
|
||||
const mem = std.mem;
|
||||
|
||||
const EqFn = fn (?[*]u8, ?[*]u8) callconv(.C) bool;
|
||||
|
@ -52,6 +53,14 @@ pub const RocList = extern struct {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn makeUniqueExtra(self: RocList, alignment: u32, element_width: usize, update_mode: UpdateMode) RocList {
|
||||
if (update_mode == .InPlace) {
|
||||
return self;
|
||||
} else {
|
||||
return self.makeUnique(alignment, element_width);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn makeUnique(self: RocList, alignment: u32, element_width: usize) RocList {
|
||||
if (self.isEmpty()) {
|
||||
return self;
|
||||
|
@ -763,7 +772,7 @@ pub fn listSwap(
|
|||
element_width: usize,
|
||||
index_1: usize,
|
||||
index_2: usize,
|
||||
can_update_in_place: bool,
|
||||
update_mode: update_mode,
|
||||
) callconv(.C) RocList {
|
||||
const size = list.len();
|
||||
if (index_1 == index_2 or index_1 >= size or index_2 >= size) {
|
||||
|
@ -772,7 +781,7 @@ pub fn listSwap(
|
|||
}
|
||||
|
||||
const newList = blk: {
|
||||
if (can_update_in_place) {
|
||||
if (update_mode == .InPlace) {
|
||||
break :blk list;
|
||||
} else {
|
||||
break :blk list.makeUnique(alignment, element_width);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue