fn newAllocEntry(s: *SafeAllocator, t: *Thread, ra: usize) error s: *SafeAllocatort: *Threadra: usize795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818fn newAllocEntry(s: *SafeAllocator, t: *Thread, ra: usize) error{OutOfMemory}!*Allocs.Entry {
if (t.free_entry) |ent| {
@branchHint(.likely);
t.free_entry = ent.toFree();
return ent;
}
if (s.allocs_entry_count - t.allocs_next != 0) {
@branchHint(.likely);
const ent = &t.allocs_first.?.entries(s)[t.allocs_next];
t.allocs_next += 1;
return ent;
}
const new_segment: *Allocs = @ptrCast(@alignCast(s.backing.rawAlloc(
(1 + s.allocs_entry_count) * @sizeOf(usize),
.of(usize),
ra,
) orelse return error.OutOfMemory));
new_segment.next = t.allocs_first;
t.allocs_first = new_segment;
t.allocs_next = 1;
return &new_segment.entries(s)[0];
}