remove padding

This commit is contained in:
Motiejus Jakštys 2022-02-21 13:48:11 +02:00 committed by Motiejus Jakštys
parent 91849c128f
commit f77d94e624

View File

@ -6,7 +6,6 @@ const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList; const ArrayList = std.ArrayList;
const cast = std.math.cast; const cast = std.math.cast;
pub const PackedUserSize = @divExact(@bitSizeOf(PackedUser), 8);
pub const PackedUser = packed struct { pub const PackedUser = packed struct {
uid: u32, uid: u32,
gid: u32, gid: u32,
@ -17,7 +16,6 @@ pub const PackedUser = packed struct {
name_is_a_suffix: bool, name_is_a_suffix: bool,
name_len: u5, name_len: u5,
gecos_len: u8, gecos_len: u8,
wip_padding: u8, // https://github.com/ziglang/zig/pull/10941
// blobSize returns the length of the blob storing string values. // blobSize returns the length of the blob storing string values.
pub fn blobLength(self: *const PackedUser) usize { pub fn blobLength(self: *const PackedUser) usize {
@ -86,7 +84,6 @@ pub const UserWriter = struct {
.name_is_a_suffix = std.mem.endsWith(u8, user.home, user.name), .name_is_a_suffix = std.mem.endsWith(u8, user.home, user.name),
.name_len = name_len, .name_len = name_len,
.gecos_len = gecos_len, .gecos_len = gecos_len,
.wip_padding = 0,
}; };
try self.appendTo.appendSlice(std.mem.asBytes(&puser)); try self.appendTo.appendSlice(std.mem.asBytes(&puser));
@ -130,10 +127,13 @@ pub const UserReader = struct {
pub fn next(it: *PackedIterator) ?PackedEntry { pub fn next(it: *PackedIterator) ?PackedEntry {
if (it.index == it.ur.blob.len) return null; if (it.index == it.ur.blob.len) return null;
assert(it.index < it.ur.blob.len); assert(it.index < it.ur.blob.len);
const endUser = it.index + PackedUserSize;
// https://github.com/ziglang/zig/issues/1095
const packedUserSizeHere = @sizeOf(PackedUser);
const endUser = it.index + packedUserSizeHere;
var packedUser = std.mem.bytesAsValue( var packedUser = std.mem.bytesAsValue(
PackedUser, PackedUser,
it.ur.blob[it.index..endUser][0..PackedUserSize], it.ur.blob[it.index..endUser][0..packedUserSizeHere],
); );
const startBlob = endUser + 1; const startBlob = endUser + 1;
const endBlob = startBlob + packedUser.blobLength(); const endBlob = startBlob + packedUser.blobLength();