authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2023-11-29 13:03:02-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-29 16:03:02-05:00
log1e42a3de89e8a4e78b76d8fc5192bbacf842c02b
treef808e14983902b38badf4751674e37573b6a876a
parentcd7ac56a5a8f79da30c56bed42c30affd9ba0a6d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Remove all usages of `std.mem.copy` and remove `std.mem.set` (#18143)


15 files changed, 24 insertions(+), 29 deletions(-)

deps/aro/aro/Type.zig+2-2
......@@ -149,8 +149,8 @@ pub const Attributed = struct {
149149 errdefer allocator.destroy(attributed_type);
150150
151151 const all_attrs = try allocator.alloc(Attribute, existing_attributes.len + attributes.len);
152 std.mem.copy(Attribute, all_attrs, existing_attributes);
153 std.mem.copy(Attribute, all_attrs[existing_attributes.len..], attributes);
152 @memcpy(all_attrs[0..existing_attributes.len], existing_attributes);
153 @memcpy(all_attrs[existing_attributes.len..], attributes);
154154
155155 attributed_type.* = .{
156156 .attributes = all_attrs,
deps/aro/backend/Ir.zig+1-1
......@@ -158,7 +158,7 @@ pub const Builder = struct {
158158 const a = b.arena.allocator();
159159 const input_refs = try a.alloc(Ref, inputs.len * 2 + 1);
160160 input_refs[0] = @enumFromInt(inputs.len);
161 std.mem.copy(Ref, input_refs[1..], std.mem.bytesAsSlice(Ref, std.mem.sliceAsBytes(inputs)));
161 @memcpy(input_refs[1..], std.mem.bytesAsSlice(Ref, std.mem.sliceAsBytes(inputs)));
162162
163163 return b.addInst(.phi, .{ .phi = .{ .ptr = input_refs.ptr } }, ty);
164164 }
doc/langref.html.in+2-2
......@@ -10509,8 +10509,8 @@ test "using an allocator" {
1050910509
1051010510fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
1051110511 const result = try allocator.alloc(u8, a.len + b.len);
10512 std.mem.copy(u8, result, a);
10513 std.mem.copy(u8, result[a.len..], b);
10512 @memcpy(result[0..a.len], a);
10513 @memcpy(result[a.len..], b);
1051410514 return result;
1051510515}
1051610516 {#code_end#}
lib/std/debug.zig+1-1
......@@ -1843,7 +1843,7 @@ pub const DebugInfo = struct {
18431843 if (coff_obj.strtabRequired()) {
18441844 var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
18451845 // openFileAbsoluteW requires the prefix to be present
1846 mem.copy(u16, name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
1846 @memcpy(name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
18471847
18481848 const process_handle = windows.kernel32.GetCurrentProcess();
18491849 const len = windows.kernel32.K32GetModuleFileNameExW(
lib/std/mem.zig+4-10
......@@ -190,10 +190,6 @@ test "Allocator.resize" {
190190 }
191191}
192192
193/// Deprecated: use `@memcpy` if the arguments do not overlap, or
194/// `copyForwards` if they do.
195pub const copy = copyForwards;
196
197193/// Copy all of source into dest at position 0.
198194/// dest.len must be >= source.len.
199195/// If the slices overlap, dest.ptr must be <= src.ptr.
......@@ -217,8 +213,6 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
217213 }
218214}
219215
220pub const set = @compileError("deprecated; use @memset instead");
221
222216/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
223217/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
224218/// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this
......@@ -2952,12 +2946,12 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con
29522946 const buf = try allocator.alloc(u8, total_len);
29532947 errdefer allocator.free(buf);
29542948
2955 copy(u8, buf, slices[0]);
2949 @memcpy(buf[0..slices[0].len], slices[0]);
29562950 var buf_index: usize = slices[0].len;
29572951 for (slices[1..]) |slice| {
2958 copy(u8, buf[buf_index..], separator);
2952 @memcpy(buf[buf_index .. buf_index + separator.len], separator);
29592953 buf_index += separator.len;
2960 copy(u8, buf[buf_index..], slice);
2954 @memcpy(buf[buf_index .. buf_index + slice.len], slice);
29612955 buf_index += slice.len;
29622956 }
29632957
......@@ -3050,7 +3044,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con
30503044
30513045 var buf_index: usize = 0;
30523046 for (slices) |slice| {
3053 copy(T, buf[buf_index..], slice);
3047 @memcpy(buf[buf_index .. buf_index + slice.len], slice);
30543048 buf_index += slice.len;
30553049 }
30563050
lib/std/os/windows/test.zig+1-1
......@@ -16,7 +16,7 @@ fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !windows.PathSpace {
1616
1717 var path_space: windows.PathSpace = undefined;
1818 const out_path = out.Buffer[0 .. out.Length / 2];
19 std.mem.copy(u16, path_space.data[0..], out_path);
19 @memcpy(path_space.data[0..out_path.len], out_path);
2020 path_space.len = out.Length / 2;
2121 path_space.data[path_space.len] = 0;
2222
src/link/MachO/uuid.zig+1-1
......@@ -22,7 +22,7 @@ pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[
2222 defer comp.gpa.free(final_buffer);
2323
2424 for (hashes, 0..) |hash, i| {
25 mem.copy(u8, final_buffer[i * Md5.digest_length ..][0..Md5.digest_length], &hash);
25 @memcpy(final_buffer[i * Md5.digest_length ..][0..Md5.digest_length], &hash);
2626 }
2727
2828 Md5.hash(final_buffer, out, .{});
src/resinator/cli.zig+2-2
......@@ -207,8 +207,8 @@ pub const Options = struct {
207207 cwd.access(options.input_filename, .{}) catch |err| switch (err) {
208208 error.FileNotFound => {
209209 var filename_bytes = try options.allocator.alloc(u8, options.input_filename.len + 3);
210 std.mem.copy(u8, filename_bytes, options.input_filename);
211 std.mem.copy(u8, filename_bytes[filename_bytes.len - 3 ..], ".rc");
210 @memcpy(filename_bytes[0 .. filename_bytes.len - 3], options.input_filename);
211 @memcpy(filename_bytes[filename_bytes.len - 3 ..], ".rc");
212212 options.allocator.free(options.input_filename);
213213 options.input_filename = filename_bytes;
214214 },
src/resinator/compile.zig+1-1
......@@ -2890,7 +2890,7 @@ pub fn HeaderSlurpingReader(comptime size: usize, comptime ReaderType: anytype)
28902890 if (self.bytes_read < size) {
28912891 const bytes_to_add = @min(amt, size - self.bytes_read);
28922892 const end_index = self.bytes_read + bytes_to_add;
2893 std.mem.copy(u8, self.slurped_header[self.bytes_read..end_index], buf[0..bytes_to_add]);
2893 @memcpy(self.slurped_header[self.bytes_read..end_index], buf[0..bytes_to_add]);
28942894 }
28952895 self.bytes_read +|= amt;
28962896 return amt;
src/resinator/lang.zig+2-2
......@@ -140,9 +140,9 @@ test "exhaustive tagToId" {
140140 writer.writeAll(parsed_sort.suffix.?) catch unreachable;
141141 const expected_field_name = comptime field: {
142142 var name_buf: [5]u8 = undefined;
143 std.mem.copy(u8, &name_buf, parsed_sort.language_code);
143 @memcpy(&name_buf[0..parsed_sort.language_code.len], parsed_sort.language_code);
144144 name_buf[2] = '_';
145 std.mem.copy(u8, name_buf[3..], parsed_sort.country_code.?);
145 @memcpy(name_buf[3..], parsed_sort.country_code.?);
146146 break :field name_buf;
147147 };
148148 const expected = @field(LanguageId, &expected_field_name);
src/resinator/source_mapping.zig+1-1
......@@ -476,7 +476,7 @@ pub const SourceMappings = struct {
476476
477477 const after_collapsed_start = line_num + num_following_lines_to_collapse;
478478 const new_num_lines = self.mapping.items.len - num_following_lines_to_collapse;
479 std.mem.copy(SourceSpan, self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);
479 std.mem.copyForwards(SourceSpan, self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);
480480
481481 self.mapping.items.len = new_num_lines;
482482 }
test/behavior/for.zig+1-1
......@@ -156,7 +156,7 @@ test "for loop with pointer elem var" {
156156
157157 const source = "abcdefg";
158158 var target: [source.len]u8 = undefined;
159 mem.copy(u8, target[0..], source);
159 @memcpy(target[0..], source);
160160 mangleString(target[0..]);
161161 try expect(mem.eql(u8, &target, "bcdefgh"));
162162
test/behavior/ptrcast.zig+2-1
......@@ -265,7 +265,8 @@ test "comptime @ptrCast a subset of an array, then write through it" {
265265 var buff: [16]u8 align(4) = undefined;
266266 const len_bytes = @as(*u32, @ptrCast(&buff));
267267 len_bytes.* = 16;
268 std.mem.copy(u8, buff[4..], "abcdef");
268 const source = "abcdef";
269 @memcpy(buff[4 .. 4 + source.len], source);
269270 }
270271}
271272
test/behavior/threadlocal.zig+1-1
......@@ -35,7 +35,7 @@ test "pointer to thread local array" {
3535 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3636
3737 const s = "Hello world";
38 std.mem.copy(u8, buffer[0..], s);
38 @memcpy(buffer[0..s.len], s);
3939 try std.testing.expectEqualSlices(u8, buffer[0..], s);
4040}
4141
tools/update-license-headers.zig+2-2
......@@ -39,8 +39,8 @@ pub fn main() !void {
3939 const truncated_source = source[expected_header.len..];
4040
4141 const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);
42 std.mem.copy(u8, new_source, new_header);
43 std.mem.copy(u8, new_source[new_header.len..], truncated_source);
42 @memcpy(new_source[0..new_source.len], new_header);
43 @memcpy(new_source[new_header.len .. new_header.len + truncated_source.len], truncated_source);
4444
4545 try dir.writeFile(entry.path, new_source);
4646 }