adding branch hinting to debug allocator
This commit is contained in:
@@ -11,6 +11,7 @@ const Alignment = std.mem.Alignment;
|
|||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
|
/// Global debug allocator for leaks detection purpose
|
||||||
pub var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
|
pub var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
|
||||||
|
|
||||||
callbacks: ?vk.AllocationCallbacks,
|
callbacks: ?vk.AllocationCallbacks,
|
||||||
@@ -27,7 +28,7 @@ pub fn init(callbacks: ?*const vk.AllocationCallbacks, scope: vk.SystemAllocatio
|
|||||||
pub fn allocator(self: *const Self) Allocator {
|
pub fn allocator(self: *const Self) Allocator {
|
||||||
if (self.callbacks != null) {
|
if (self.callbacks != null) {
|
||||||
return .{
|
return .{
|
||||||
.ptr = @constCast(self),
|
.ptr = undefined,
|
||||||
.vtable = &.{
|
.vtable = &.{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.resize = resize,
|
.resize = resize,
|
||||||
@@ -37,10 +38,12 @@ pub fn allocator(self: *const Self) Allocator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (std.process.hasEnvVarConstant(DRIVER_DEBUG_ALLOCATOR_ENV_NAME) or builtin.mode == std.builtin.OptimizeMode.Debug)
|
if (std.process.hasEnvVarConstant(DRIVER_DEBUG_ALLOCATOR_ENV_NAME) or builtin.mode == std.builtin.OptimizeMode.Debug) {
|
||||||
debug_allocator.allocator()
|
@branchHint(.unlikely);
|
||||||
else
|
return debug_allocator.allocator();
|
||||||
std.heap.c_allocator;
|
} else {
|
||||||
|
return std.heap.c_allocator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc(context: *anyopaque, len: usize, alignment: Alignment, _: usize) ?[*]u8 {
|
fn alloc(context: *anyopaque, len: usize, alignment: Alignment, _: usize) ?[*]u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user