mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Remove all usages of std.mem.copy and remove std.mem.set (#18143)
This commit is contained in:
parent
cd7ac56a5a
commit
1e42a3de89
15 changed files with 24 additions and 29 deletions
4
deps/aro/aro/Type.zig
vendored
4
deps/aro/aro/Type.zig
vendored
|
|
@ -149,8 +149,8 @@ pub const Attributed = struct {
|
|||
errdefer allocator.destroy(attributed_type);
|
||||
|
||||
const all_attrs = try allocator.alloc(Attribute, existing_attributes.len + attributes.len);
|
||||
std.mem.copy(Attribute, all_attrs, existing_attributes);
|
||||
std.mem.copy(Attribute, all_attrs[existing_attributes.len..], attributes);
|
||||
@memcpy(all_attrs[0..existing_attributes.len], existing_attributes);
|
||||
@memcpy(all_attrs[existing_attributes.len..], attributes);
|
||||
|
||||
attributed_type.* = .{
|
||||
.attributes = all_attrs,
|
||||
|
|
|
|||
2
deps/aro/backend/Ir.zig
vendored
2
deps/aro/backend/Ir.zig
vendored
|
|
@ -158,7 +158,7 @@ pub const Builder = struct {
|
|||
const a = b.arena.allocator();
|
||||
const input_refs = try a.alloc(Ref, inputs.len * 2 + 1);
|
||||
input_refs[0] = @enumFromInt(inputs.len);
|
||||
std.mem.copy(Ref, input_refs[1..], std.mem.bytesAsSlice(Ref, std.mem.sliceAsBytes(inputs)));
|
||||
@memcpy(input_refs[1..], std.mem.bytesAsSlice(Ref, std.mem.sliceAsBytes(inputs)));
|
||||
|
||||
return b.addInst(.phi, .{ .phi = .{ .ptr = input_refs.ptr } }, ty);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10509,8 +10509,8 @@ test "using an allocator" {
|
|||
|
||||
fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
|
||||
const result = try allocator.alloc(u8, a.len + b.len);
|
||||
std.mem.copy(u8, result, a);
|
||||
std.mem.copy(u8, result[a.len..], b);
|
||||
@memcpy(result[0..a.len], a);
|
||||
@memcpy(result[a.len..], b);
|
||||
return result;
|
||||
}
|
||||
{#code_end#}
|
||||
|
|
|
|||
|
|
@ -1843,7 +1843,7 @@ pub const DebugInfo = struct {
|
|||
if (coff_obj.strtabRequired()) {
|
||||
var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
|
||||
// openFileAbsoluteW requires the prefix to be present
|
||||
mem.copy(u16, name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
|
||||
@memcpy(name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
|
||||
|
||||
const process_handle = windows.kernel32.GetCurrentProcess();
|
||||
const len = windows.kernel32.K32GetModuleFileNameExW(
|
||||
|
|
|
|||
|
|
@ -190,10 +190,6 @@ test "Allocator.resize" {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deprecated: use `@memcpy` if the arguments do not overlap, or
|
||||
/// `copyForwards` if they do.
|
||||
pub const copy = copyForwards;
|
||||
|
||||
/// Copy all of source into dest at position 0.
|
||||
/// dest.len must be >= source.len.
|
||||
/// 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 {
|
|||
}
|
||||
}
|
||||
|
||||
pub const set = @compileError("deprecated; use @memset instead");
|
||||
|
||||
/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
|
||||
/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
|
||||
/// 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
|
|||
const buf = try allocator.alloc(u8, total_len);
|
||||
errdefer allocator.free(buf);
|
||||
|
||||
copy(u8, buf, slices[0]);
|
||||
@memcpy(buf[0..slices[0].len], slices[0]);
|
||||
var buf_index: usize = slices[0].len;
|
||||
for (slices[1..]) |slice| {
|
||||
copy(u8, buf[buf_index..], separator);
|
||||
@memcpy(buf[buf_index .. buf_index + separator.len], separator);
|
||||
buf_index += separator.len;
|
||||
copy(u8, buf[buf_index..], slice);
|
||||
@memcpy(buf[buf_index .. buf_index + slice.len], slice);
|
||||
buf_index += slice.len;
|
||||
}
|
||||
|
||||
|
|
@ -3050,7 +3044,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con
|
|||
|
||||
var buf_index: usize = 0;
|
||||
for (slices) |slice| {
|
||||
copy(T, buf[buf_index..], slice);
|
||||
@memcpy(buf[buf_index .. buf_index + slice.len], slice);
|
||||
buf_index += slice.len;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !windows.PathSpace {
|
|||
|
||||
var path_space: windows.PathSpace = undefined;
|
||||
const out_path = out.Buffer[0 .. out.Length / 2];
|
||||
std.mem.copy(u16, path_space.data[0..], out_path);
|
||||
@memcpy(path_space.data[0..out_path.len], out_path);
|
||||
path_space.len = out.Length / 2;
|
||||
path_space.data[path_space.len] = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[
|
|||
defer comp.gpa.free(final_buffer);
|
||||
|
||||
for (hashes, 0..) |hash, i| {
|
||||
mem.copy(u8, final_buffer[i * Md5.digest_length ..][0..Md5.digest_length], &hash);
|
||||
@memcpy(final_buffer[i * Md5.digest_length ..][0..Md5.digest_length], &hash);
|
||||
}
|
||||
|
||||
Md5.hash(final_buffer, out, .{});
|
||||
|
|
|
|||
|
|
@ -207,8 +207,8 @@ pub const Options = struct {
|
|||
cwd.access(options.input_filename, .{}) catch |err| switch (err) {
|
||||
error.FileNotFound => {
|
||||
var filename_bytes = try options.allocator.alloc(u8, options.input_filename.len + 3);
|
||||
std.mem.copy(u8, filename_bytes, options.input_filename);
|
||||
std.mem.copy(u8, filename_bytes[filename_bytes.len - 3 ..], ".rc");
|
||||
@memcpy(filename_bytes[0 .. filename_bytes.len - 3], options.input_filename);
|
||||
@memcpy(filename_bytes[filename_bytes.len - 3 ..], ".rc");
|
||||
options.allocator.free(options.input_filename);
|
||||
options.input_filename = filename_bytes;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2890,7 +2890,7 @@ pub fn HeaderSlurpingReader(comptime size: usize, comptime ReaderType: anytype)
|
|||
if (self.bytes_read < size) {
|
||||
const bytes_to_add = @min(amt, size - self.bytes_read);
|
||||
const end_index = self.bytes_read + bytes_to_add;
|
||||
std.mem.copy(u8, self.slurped_header[self.bytes_read..end_index], buf[0..bytes_to_add]);
|
||||
@memcpy(self.slurped_header[self.bytes_read..end_index], buf[0..bytes_to_add]);
|
||||
}
|
||||
self.bytes_read +|= amt;
|
||||
return amt;
|
||||
|
|
|
|||
|
|
@ -140,9 +140,9 @@ test "exhaustive tagToId" {
|
|||
writer.writeAll(parsed_sort.suffix.?) catch unreachable;
|
||||
const expected_field_name = comptime field: {
|
||||
var name_buf: [5]u8 = undefined;
|
||||
std.mem.copy(u8, &name_buf, parsed_sort.language_code);
|
||||
@memcpy(&name_buf[0..parsed_sort.language_code.len], parsed_sort.language_code);
|
||||
name_buf[2] = '_';
|
||||
std.mem.copy(u8, name_buf[3..], parsed_sort.country_code.?);
|
||||
@memcpy(name_buf[3..], parsed_sort.country_code.?);
|
||||
break :field name_buf;
|
||||
};
|
||||
const expected = @field(LanguageId, &expected_field_name);
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ pub const SourceMappings = struct {
|
|||
|
||||
const after_collapsed_start = line_num + num_following_lines_to_collapse;
|
||||
const new_num_lines = self.mapping.items.len - num_following_lines_to_collapse;
|
||||
std.mem.copy(SourceSpan, self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);
|
||||
std.mem.copyForwards(SourceSpan, self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);
|
||||
|
||||
self.mapping.items.len = new_num_lines;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ test "for loop with pointer elem var" {
|
|||
|
||||
const source = "abcdefg";
|
||||
var target: [source.len]u8 = undefined;
|
||||
mem.copy(u8, target[0..], source);
|
||||
@memcpy(target[0..], source);
|
||||
mangleString(target[0..]);
|
||||
try expect(mem.eql(u8, &target, "bcdefgh"));
|
||||
|
||||
|
|
|
|||
|
|
@ -265,7 +265,8 @@ test "comptime @ptrCast a subset of an array, then write through it" {
|
|||
var buff: [16]u8 align(4) = undefined;
|
||||
const len_bytes = @as(*u32, @ptrCast(&buff));
|
||||
len_bytes.* = 16;
|
||||
std.mem.copy(u8, buff[4..], "abcdef");
|
||||
const source = "abcdef";
|
||||
@memcpy(buff[4 .. 4 + source.len], source);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ test "pointer to thread local array" {
|
|||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
||||
const s = "Hello world";
|
||||
std.mem.copy(u8, buffer[0..], s);
|
||||
@memcpy(buffer[0..s.len], s);
|
||||
try std.testing.expectEqualSlices(u8, buffer[0..], s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ pub fn main() !void {
|
|||
const truncated_source = source[expected_header.len..];
|
||||
|
||||
const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);
|
||||
std.mem.copy(u8, new_source, new_header);
|
||||
std.mem.copy(u8, new_source[new_header.len..], truncated_source);
|
||||
@memcpy(new_source[0..new_source.len], new_header);
|
||||
@memcpy(new_source[new_header.len .. new_header.len + truncated_source.len], truncated_source);
|
||||
|
||||
try dir.writeFile(entry.path, new_source);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue