Skip to content

Commit

Permalink
Refactor AccountsDB.init
Browse files Browse the repository at this point in the history
  • Loading branch information
InKryption committed Jun 12, 2024
1 parent bc2d076 commit e727b22
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ pub const AccountsDB = struct {
config.storage_cache_size,
);

const maybe_disk_allocator: ?*DiskMemoryAllocator, //
const maybe_disk_allocator_ptr: ?*DiskMemoryAllocator, //
const reference_allocator: std.mem.Allocator //
= blk: {
const disk_index_path = config.disk_index_path orelse break :blk .{ null, std.heap.page_allocator };
const ptr = try allocator.create(DiskMemoryAllocator);
errdefer allocator.destroy(ptr);
ptr.* = try DiskMemoryAllocator.init(disk_index_path);
break :blk .{ ptr, ptr.allocator() };
if (config.disk_index_path) |disk_index_path| {
const ptr = try allocator.create(DiskMemoryAllocator);
errdefer allocator.destroy(ptr);
ptr.* = try DiskMemoryAllocator.init(disk_index_path);
break :blk .{ ptr, ptr.allocator() };
} else {
break :blk .{ null, std.heap.page_allocator };
}
};

const account_index = try AccountIndex.init(
Expand All @@ -99,7 +102,7 @@ pub const AccountsDB = struct {

return .{
.allocator = allocator,
.disk_allocator_ptr = maybe_disk_allocator,
.disk_allocator_ptr = maybe_disk_allocator_ptr,
.storage = storage,
.account_index = account_index,
.logger = logger,
Expand Down

0 comments on commit e727b22

Please sign in to comment.