Skip to content

Commit 9d4ab1e

Browse files
committed
Refine some bincode type stuff and style things
1 parent f5044f9 commit 9d4ab1e

File tree

15 files changed

+279
-153
lines changed

15 files changed

+279
-153
lines changed

scripts/style.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ def unused_imports(args, files_to_check):
131131

132132

133133
files_excluded_from_line_length_check = [
134-
"src/bincode/arraylist.zig",
135-
"src/bincode/bincode.zig",
136-
"src/bincode/int.zig",
137-
"src/bincode/shortvec.zig",
138134
"src/bloom/bit_set.zig",
139135
"src/bloom/bit_vec.zig",
140136
"src/bloom/bitvec.zig",

src/accountsdb/buffer_pool.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ pub const AccountDataHandle = union(enum) {
11121112
writer: anytype,
11131113
read_handle: anytype,
11141114
params: bincode.Params,
1115-
) anyerror!void {
1115+
) !void {
11161116
// we want to serialise it as if it's a slice
11171117
try bincode.write(writer, @as(u64, read_handle.len()), params);
11181118

@@ -1126,12 +1126,12 @@ pub const AccountDataHandle = union(enum) {
11261126
alloc: std.mem.Allocator,
11271127
reader: anytype,
11281128
params: bincode.Params,
1129-
) anyerror!AccountDataHandle {
1129+
) !AccountDataHandle {
11301130
const data = try bincode.read(alloc, []u8, reader, params);
11311131
return AccountDataHandle.initAllocatedOwned(data);
11321132
}
11331133

1134-
fn bincodeFree(allocator: std.mem.Allocator, read_handle: anytype) void {
1134+
fn bincodeFree(allocator: std.mem.Allocator, read_handle: AccountDataHandle) void {
11351135
read_handle.deinit(allocator);
11361136
}
11371137
};

src/accountsdb/snapshots.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ pub const ExtraFields = struct {
263263
return extra_fields;
264264
}
265265

266-
fn bincodeFree(allocator: std.mem.Allocator, data: anytype) void {
267-
comptime if (@TypeOf(data) == ExtraFields) unreachable;
266+
fn bincodeFree(allocator: std.mem.Allocator, data: ExtraFields) void {
268267
data.deinit(allocator);
269268
}
270269
};
@@ -488,7 +487,7 @@ pub const AccountsDbFields = struct {
488487
};
489488
}
490489

491-
fn bincodeWrite(writer: anytype, data: anytype, params: bincode.Params) !void {
490+
fn bincodeWrite(writer: anytype, data: AccountsDbFields, params: bincode.Params) !void {
492491
comptime if (@TypeOf(data) != AccountsDbFields) unreachable;
493492

494493
{
@@ -510,7 +509,7 @@ pub const AccountsDbFields = struct {
510509
try bincode.write(writer, data.rooted_slot_hashes, params);
511510
}
512511

513-
fn bincodeFree(allocator: std.mem.Allocator, data: anytype) void {
512+
fn bincodeFree(allocator: std.mem.Allocator, data: AccountsDbFields) void {
514513
data.deinit(allocator);
515514
}
516515
};

src/bincode/arraylist.zig

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
1313
const list_info = arrayListInfo(List).?;
1414

1515
const S = struct {
16-
fn serialize(writer: anytype, data: anytype, params: bincode.Params) anyerror!void {
16+
fn serialize(writer: anytype, data: List, params: bincode.Params) !void {
1717
try bincode.write(writer, data.items.len, params);
1818
for (data.items) |item| try bincode.write(writer, item, params);
1919
}
@@ -22,17 +22,21 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
2222
allocator: std.mem.Allocator,
2323
reader: anytype,
2424
params: Params,
25-
) anyerror!List {
26-
const len = (try readIntAsLength(usize, reader, params)) orelse return error.ArrayListTooBig;
25+
) !List {
26+
const maybe_len = try readIntAsLength(usize, reader, params);
27+
const len = maybe_len orelse return error.ArrayListTooBig;
2728

2829
var data: List = try List.initCapacity(allocator, len);
2930
errdefer free(allocator, data);
3031

31-
for (0..len) |_| data.appendAssumeCapacity(try bincode.read(allocator, list_info.Elem, reader, params));
32+
for (0..len) |_| {
33+
const elem = try bincode.read(allocator, list_info.Elem, reader, params);
34+
data.appendAssumeCapacity(elem);
35+
}
3236
return data;
3337
}
3438

35-
fn free(allocator: std.mem.Allocator, data: anytype) void {
39+
fn free(allocator: std.mem.Allocator, data: List) void {
3640
var copy = data;
3741
for (copy.items) |value| bincode.free(allocator, value);
3842
switch (list_info.management) {
@@ -51,9 +55,15 @@ pub fn standardConfig(comptime List: type) bincode.FieldConfig(List) {
5155

5256
/// Defaults the field of type `List` to an empty state on EOF.
5357
pub fn defaultOnEofConfig(comptime List: type) bincode.FieldConfig(List) {
54-
const al_info = arrayListInfo(List) orelse @compileError("Expected std.ArrayList[Unmanaged]Aligned(T), got " ++ @typeName(List));
58+
const al_info = arrayListInfo(List) orelse @compileError(
59+
"Expected std.ArrayList[Unmanaged]Aligned(T), got " ++ @typeName(List),
60+
);
5561
const S = struct {
56-
fn deserialize(allocator: std.mem.Allocator, reader: anytype, params: bincode.Params) anyerror!List {
62+
fn deserialize(
63+
allocator: std.mem.Allocator,
64+
reader: anytype,
65+
params: bincode.Params,
66+
) !List {
5767
const len = if (bincode.readIntAsLength(usize, reader, params)) |maybe_len|
5868
(maybe_len orelse return error.ArrayListTooBig)
5969
else |err| switch (err) {
@@ -74,7 +84,7 @@ pub fn defaultOnEofConfig(comptime List: type) bincode.FieldConfig(List) {
7484
};
7585
}
7686

77-
fn free(allocator: std.mem.Allocator, data: anytype) void {
87+
fn free(allocator: std.mem.Allocator, data: List) void {
7888
var copy = data;
7989
for (copy.items) |value| bincode.free(allocator, value);
8090
switch (al_info.management) {

0 commit comments

Comments
 (0)