From 570bf3e39ab84d05fc5c1d7f4b35f95062219cc9 Mon Sep 17 00:00:00 2001 From: Trevor Berrange Sanchez Date: Mon, 3 Jun 2024 19:05:44 +0200 Subject: [PATCH] Style fixes & refactors --- src/gossip/service.zig | 14 ++++++++------ src/net/socket_utils.zig | 7 ++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/gossip/service.zig b/src/gossip/service.zig index 075a813ae..af161fb73 100644 --- a/src/gossip/service.zig +++ b/src/gossip/service.zig @@ -436,12 +436,14 @@ pub const GossipService = struct { defer self.allocator.free(tasks); // pre-allocate all the tasks - for (tasks) |*task| task.entry = .{ - .allocator = task_allocator, - .verified_incoming_channel = self.verified_incoming_channel, - .packet_batch = undefined, - .logger = self.logger, - }; + for (tasks) |*task| { + task.entry = .{ + .allocator = task_allocator, + .verified_incoming_channel = self.verified_incoming_channel, + .packet_batch = undefined, + .logger = self.logger, + }; + } while (!self.exit.load(.unordered)) { const maybe_packet_batches = try self.packet_incoming_channel.try_drain(); diff --git a/src/net/socket_utils.zig b/src/net/socket_utils.zig index fa05a7e98..22e94fde4 100644 --- a/src/net/socket_utils.zig +++ b/src/net/socket_utils.zig @@ -27,8 +27,6 @@ pub fn readSocket( while (!exit.load(.unordered)) { // init a new batch - // var count: usize = 0; - // const capacity = PACKETS_PER_BATCH; var packet_batch = try std.ArrayList(Packet).initCapacity( allocator, PACKETS_PER_BATCH, @@ -72,12 +70,11 @@ pub fn sendSocket( while (!exit.load(.unordered)) { const maybe_packet_batches = try outgoing_channel.try_drain(); - if (maybe_packet_batches == null) { + const packet_batches = maybe_packet_batches orelse { // sleep for 1ms // std.time.sleep(std.time.ns_per_ms * 1); continue; - } - const packet_batches = maybe_packet_batches.?; + }; defer { for (packet_batches) |*packet_batch| { packet_batch.deinit();