aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-04-13 21:44:40 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-04-25 11:23:40 -0700
commita5c910adb610ae530db99f10aa77aaed3e85e830 (patch)
tree5c3f72dbac50fc9f09608be3d7ea328c629c00a0 /lib/std/array_list.zig
parent8d88dcdc61c61e3410138f4402482131f5074a80 (diff)
downloadzig-a5c910adb610ae530db99f10aa77aaed3e85e830.tar.gz
zig-a5c910adb610ae530db99f10aa77aaed3e85e830.zip
change semantics of `@memcpy` and `@memset`
Now they use slices or array pointers with any element type instead of requiring byte pointers. This is a breaking enhancement to the language. The safety check for overlapping pointers will be implemented in a future commit. closes #14040
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 1695e2bd87..1791482bc4 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -121,7 +121,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
- @memset(@ptrCast([*]u8, self.items.ptr), undefined, self.items.len * @sizeOf(T));
+ @memset(self.items, undefined);
self.clearAndFree();
return new_memory;
}
@@ -281,11 +281,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
- @memcpy(
- @ptrCast([*]align(@alignOf(T)) u8, self.items.ptr + old_len),
- @ptrCast([*]const u8, items.ptr),
- items.len * @sizeOf(T),
- );
+ @memcpy(self.items[old_len..][0..items.len], items);
}
pub const Writer = if (T != u8)
@@ -601,7 +597,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
- @memset(@ptrCast([*]u8, self.items.ptr), undefined, self.items.len * @sizeOf(T));
+ @memset(self.items, undefined);
self.clearAndFree(allocator);
return new_memory;
}
@@ -740,11 +736,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
- @memcpy(
- @ptrCast([*]align(@alignOf(T)) u8, self.items.ptr + old_len),
- @ptrCast([*]const u8, items.ptr),
- items.len * @sizeOf(T),
- );
+ @memcpy(self.items[old_len..][0..items.len], items);
}
pub const WriterContext = struct {