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 {...@@ -149,8 +149,8 @@ pub const Attributed = struct {
149 errdefer allocator.destroy(attributed_type);149 errdefer allocator.destroy(attributed_type);
150150
151 const all_attrs = try allocator.alloc(Attribute, existing_attributes.len + attributes.len);151 const all_attrs = try allocator.alloc(Attribute, existing_attributes.len + attributes.len);
152 std.mem.copy(Attribute, all_attrs, existing_attributes);152 @memcpy(all_attrs[0..existing_attributes.len], existing_attributes);
153 std.mem.copy(Attribute, all_attrs[existing_attributes.len..], attributes);153 @memcpy(all_attrs[existing_attributes.len..], attributes);
154154
155 attributed_type.* = .{155 attributed_type.* = .{
156 .attributes = all_attrs,156 .attributes = all_attrs,
deps/aro/backend/Ir.zig+1-1
...@@ -158,7 +158,7 @@ pub const Builder = struct {...@@ -158,7 +158,7 @@ pub const Builder = struct {
158 const a = b.arena.allocator();158 const a = b.arena.allocator();
159 const input_refs = try a.alloc(Ref, inputs.len * 2 + 1);159 const input_refs = try a.alloc(Ref, inputs.len * 2 + 1);
160 input_refs[0] = @enumFromInt(inputs.len);160 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
163 return b.addInst(.phi, .{ .phi = .{ .ptr = input_refs.ptr } }, ty);163 return b.addInst(.phi, .{ .phi = .{ .ptr = input_refs.ptr } }, ty);
164 }164 }
doc/langref.html.in+2-2
...@@ -10509,8 +10509,8 @@ test "using an allocator" {...@@ -10509,8 +10509,8 @@ test "using an allocator" {
1050910509
10510fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {10510fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
10511 const result = try allocator.alloc(u8, a.len + b.len);10511 const result = try allocator.alloc(u8, a.len + b.len);
10512 std.mem.copy(u8, result, a);10512 @memcpy(result[0..a.len], a);
10513 std.mem.copy(u8, result[a.len..], b);10513 @memcpy(result[a.len..], b);
10514 return result;10514 return result;
10515}10515}
10516 {#code_end#}10516 {#code_end#}
lib/std/debug.zig+1-1
...@@ -1843,7 +1843,7 @@ pub const DebugInfo = struct {...@@ -1843,7 +1843,7 @@ pub const DebugInfo = struct {
1843 if (coff_obj.strtabRequired()) {1843 if (coff_obj.strtabRequired()) {
1844 var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;1844 var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
1845 // openFileAbsoluteW requires the prefix to be present1845 // openFileAbsoluteW requires the prefix to be present
1846 mem.copy(u16, name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });1846 @memcpy(name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
18471847
1848 const process_handle = windows.kernel32.GetCurrentProcess();1848 const process_handle = windows.kernel32.GetCurrentProcess();
1849 const len = windows.kernel32.K32GetModuleFileNameExW(1849 const len = windows.kernel32.K32GetModuleFileNameExW(
lib/std/mem.zig+4-10
...@@ -190,10 +190,6 @@ test "Allocator.resize" {...@@ -190,10 +190,6 @@ test "Allocator.resize" {
190 }190 }
191}191}
192192
193/// Deprecated: use `@memcpy` if the arguments do not overlap, or
194/// `copyForwards` if they do.
195pub const copy = copyForwards;
196
197/// Copy all of source into dest at position 0.193/// Copy all of source into dest at position 0.
198/// dest.len must be >= source.len.194/// dest.len must be >= source.len.
199/// If the slices overlap, dest.ptr must be <= src.ptr.195/// 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 {...@@ -217,8 +213,6 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
217 }213 }
218}214}
219215
220pub const set = @compileError("deprecated; use @memset instead");
221
222/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.216/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
223/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when217/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
224/// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this218/// 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...@@ -2952,12 +2946,12 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con
2952 const buf = try allocator.alloc(u8, total_len);2946 const buf = try allocator.alloc(u8, total_len);
2953 errdefer allocator.free(buf);2947 errdefer allocator.free(buf);
29542948
2955 copy(u8, buf, slices[0]);2949 @memcpy(buf[0..slices[0].len], slices[0]);
2956 var buf_index: usize = slices[0].len;2950 var buf_index: usize = slices[0].len;
2957 for (slices[1..]) |slice| {2951 for (slices[1..]) |slice| {
2958 copy(u8, buf[buf_index..], separator);2952 @memcpy(buf[buf_index .. buf_index + separator.len], separator);
2959 buf_index += separator.len;2953 buf_index += separator.len;
2960 copy(u8, buf[buf_index..], slice);2954 @memcpy(buf[buf_index .. buf_index + slice.len], slice);
2961 buf_index += slice.len;2955 buf_index += slice.len;
2962 }2956 }
29632957
...@@ -3050,7 +3044,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con...@@ -3050,7 +3044,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con
30503044
3051 var buf_index: usize = 0;3045 var buf_index: usize = 0;
3052 for (slices) |slice| {3046 for (slices) |slice| {
3053 copy(T, buf[buf_index..], slice);3047 @memcpy(buf[buf_index .. buf_index + slice.len], slice);
3054 buf_index += slice.len;3048 buf_index += slice.len;
3055 }3049 }
30563050
lib/std/os/windows/test.zig+1-1
...@@ -16,7 +16,7 @@ fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !windows.PathSpace {...@@ -16,7 +16,7 @@ fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !windows.PathSpace {
1616
17 var path_space: windows.PathSpace = undefined;17 var path_space: windows.PathSpace = undefined;
18 const out_path = out.Buffer[0 .. out.Length / 2];18 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);
20 path_space.len = out.Length / 2;20 path_space.len = out.Length / 2;
21 path_space.data[path_space.len] = 0;21 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: *[...@@ -22,7 +22,7 @@ pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[
22 defer comp.gpa.free(final_buffer);22 defer comp.gpa.free(final_buffer);
2323
24 for (hashes, 0..) |hash, i| {24 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);
26 }26 }
2727
28 Md5.hash(final_buffer, out, .{});28 Md5.hash(final_buffer, out, .{});
src/resinator/cli.zig+2-2
...@@ -207,8 +207,8 @@ pub const Options = struct {...@@ -207,8 +207,8 @@ pub const Options = struct {
207 cwd.access(options.input_filename, .{}) catch |err| switch (err) {207 cwd.access(options.input_filename, .{}) catch |err| switch (err) {
208 error.FileNotFound => {208 error.FileNotFound => {
209 var filename_bytes = try options.allocator.alloc(u8, options.input_filename.len + 3);209 var filename_bytes = try options.allocator.alloc(u8, options.input_filename.len + 3);
210 std.mem.copy(u8, filename_bytes, options.input_filename);210 @memcpy(filename_bytes[0 .. filename_bytes.len - 3], options.input_filename);
211 std.mem.copy(u8, filename_bytes[filename_bytes.len - 3 ..], ".rc");211 @memcpy(filename_bytes[filename_bytes.len - 3 ..], ".rc");
212 options.allocator.free(options.input_filename);212 options.allocator.free(options.input_filename);
213 options.input_filename = filename_bytes;213 options.input_filename = filename_bytes;
214 },214 },
src/resinator/compile.zig+1-1
...@@ -2890,7 +2890,7 @@ pub fn HeaderSlurpingReader(comptime size: usize, comptime ReaderType: anytype)...@@ -2890,7 +2890,7 @@ pub fn HeaderSlurpingReader(comptime size: usize, comptime ReaderType: anytype)
2890 if (self.bytes_read < size) {2890 if (self.bytes_read < size) {
2891 const bytes_to_add = @min(amt, size - self.bytes_read);2891 const bytes_to_add = @min(amt, size - self.bytes_read);
2892 const end_index = self.bytes_read + bytes_to_add;2892 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]);
2894 }2894 }
2895 self.bytes_read +|= amt;2895 self.bytes_read +|= amt;
2896 return amt;2896 return amt;
src/resinator/lang.zig+2-2
...@@ -140,9 +140,9 @@ test "exhaustive tagToId" {...@@ -140,9 +140,9 @@ test "exhaustive tagToId" {
140 writer.writeAll(parsed_sort.suffix.?) catch unreachable;140 writer.writeAll(parsed_sort.suffix.?) catch unreachable;
141 const expected_field_name = comptime field: {141 const expected_field_name = comptime field: {
142 var name_buf: [5]u8 = undefined;142 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);
144 name_buf[2] = '_';144 name_buf[2] = '_';
145 std.mem.copy(u8, name_buf[3..], parsed_sort.country_code.?);145 @memcpy(name_buf[3..], parsed_sort.country_code.?);
146 break :field name_buf;146 break :field name_buf;
147 };147 };
148 const expected = @field(LanguageId, &expected_field_name);148 const expected = @field(LanguageId, &expected_field_name);
src/resinator/source_mapping.zig+1-1
...@@ -476,7 +476,7 @@ pub const SourceMappings = struct {...@@ -476,7 +476,7 @@ pub const SourceMappings = struct {
476476
477 const after_collapsed_start = line_num + num_following_lines_to_collapse;477 const after_collapsed_start = line_num + num_following_lines_to_collapse;
478 const new_num_lines = self.mapping.items.len - num_following_lines_to_collapse;478 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
481 self.mapping.items.len = new_num_lines;481 self.mapping.items.len = new_num_lines;
482 }482 }
test/behavior/for.zig+1-1
...@@ -156,7 +156,7 @@ test "for loop with pointer elem var" {...@@ -156,7 +156,7 @@ test "for loop with pointer elem var" {
156156
157 const source = "abcdefg";157 const source = "abcdefg";
158 var target: [source.len]u8 = undefined;158 var target: [source.len]u8 = undefined;
159 mem.copy(u8, target[0..], source);159 @memcpy(target[0..], source);
160 mangleString(target[0..]);160 mangleString(target[0..]);
161 try expect(mem.eql(u8, &target, "bcdefgh"));161 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" {...@@ -265,7 +265,8 @@ test "comptime @ptrCast a subset of an array, then write through it" {
265 var buff: [16]u8 align(4) = undefined;265 var buff: [16]u8 align(4) = undefined;
266 const len_bytes = @as(*u32, @ptrCast(&buff));266 const len_bytes = @as(*u32, @ptrCast(&buff));
267 len_bytes.* = 16;267 len_bytes.* = 16;
268 std.mem.copy(u8, buff[4..], "abcdef");268 const source = "abcdef";
269 @memcpy(buff[4 .. 4 + source.len], source);
269 }270 }
270}271}
271272
test/behavior/threadlocal.zig+1-1
...@@ -35,7 +35,7 @@ test "pointer to thread local array" {...@@ -35,7 +35,7 @@ test "pointer to thread local array" {
35 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO35 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3636
37 const s = "Hello world";37 const s = "Hello world";
38 std.mem.copy(u8, buffer[0..], s);38 @memcpy(buffer[0..s.len], s);
39 try std.testing.expectEqualSlices(u8, buffer[0..], s);39 try std.testing.expectEqualSlices(u8, buffer[0..], s);
40}40}
4141
tools/update-license-headers.zig+2-2
...@@ -39,8 +39,8 @@ pub fn main() !void {...@@ -39,8 +39,8 @@ pub fn main() !void {
39 const truncated_source = source[expected_header.len..];39 const truncated_source = source[expected_header.len..];
4040
41 const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);41 const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);
42 std.mem.copy(u8, new_source, new_header);42 @memcpy(new_source[0..new_source.len], new_header);
43 std.mem.copy(u8, new_source[new_header.len..], truncated_source);43 @memcpy(new_source[new_header.len .. new_header.len + truncated_source.len], truncated_source);
4444
45 try dir.writeFile(entry.path, new_source);45 try dir.writeFile(entry.path, new_source);
46 }46 }