Remove usage of do in core library

This commit is contained in:
gingerBill
2020-09-23 17:17:14 +01:00
parent 4844dd4d96
commit fc4fdd588e
45 changed files with 960 additions and 520 deletions
+23 -9
View File
@@ -46,14 +46,22 @@ Allocator :: struct {
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
alloc :: inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> rawptr {
if size == 0 do return nil;
if allocator.procedure == nil do return nil;
if size == 0 {
return nil;
}
if allocator.procedure == nil {
return nil;
}
return allocator.procedure(allocator.data, Allocator_Mode.Alloc, size, alignment, nil, 0, 0, loc);
}
free :: inline proc(ptr: rawptr, allocator := context.allocator, loc := #caller_location) {
if ptr == nil do return;
if allocator.procedure == nil do return;
if ptr == nil {
return;
}
if allocator.procedure == nil {
return;
}
allocator.procedure(allocator.data, Allocator_Mode.Free, 0, 0, ptr, 0, 0, loc);
}
@@ -129,12 +137,12 @@ new :: inline proc($T: typeid, allocator := context.allocator, loc := #caller_lo
}
new_aligned :: inline proc($T: typeid, alignment: int, allocator := context.allocator, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), alignment, allocator, loc));
if ptr != nil do ptr^ = T{};
if ptr != nil { ptr^ = T{}; }
return ptr;
}
new_clone :: inline proc(data: $T, allocator := context.allocator, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), align_of(T), allocator, loc));
if ptr != nil do ptr^ = data;
if ptr != nil { ptr^ = data; }
return ptr;
}
@@ -188,17 +196,23 @@ make :: proc{
default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment: int, allocator := context.allocator, loc := #caller_location) -> rawptr {
if old_memory == nil do return alloc(new_size, alignment, allocator, loc);
if old_memory == nil {
return alloc(new_size, alignment, allocator, loc);
}
if new_size == 0 {
free(old_memory, allocator, loc);
return nil;
}
if new_size == old_size do return old_memory;
if new_size == old_size {
return old_memory;
}
new_memory := alloc(new_size, alignment, allocator, loc);
if new_memory == nil do return nil;
if new_memory == nil {
return nil;
}
copy(new_memory, old_memory, min(old_size, new_size));
free(old_memory, allocator, loc);
+13 -7
View File
@@ -186,13 +186,15 @@ any_to_bytes :: inline proc(val: any) -> []byte {
}
kilobytes :: inline proc(x: int) -> int do return (x) * 1024;
megabytes :: inline proc(x: int) -> int do return kilobytes(x) * 1024;
gigabytes :: inline proc(x: int) -> int do return megabytes(x) * 1024;
terabytes :: inline proc(x: int) -> int do return gigabytes(x) * 1024;
kilobytes :: inline proc(x: int) -> int { return (x) * 1024; }
megabytes :: inline proc(x: int) -> int { return kilobytes(x) * 1024; }
gigabytes :: inline proc(x: int) -> int { return megabytes(x) * 1024; }
terabytes :: inline proc(x: int) -> int { return gigabytes(x) * 1024; }
is_power_of_two :: inline proc(x: uintptr) -> bool {
if x <= 0 do return false;
if x <= 0 {
return false;
}
return (x & (x-1)) == 0;
}
@@ -205,7 +207,9 @@ align_forward_uintptr :: proc(ptr, align: uintptr) -> uintptr {
p := ptr;
modulo := p & (align-1);
if modulo != 0 do p += align - modulo;
if modulo != 0 {
p += align - modulo;
}
return p;
}
@@ -264,7 +268,9 @@ calc_padding_with_header :: proc(ptr: uintptr, align: uintptr, header_size: int)
modulo := p & (a-1);
padding := uintptr(0);
if modulo != 0 do padding = a - modulo;
if modulo != 0 {
padding = a - modulo;
}
needed_space := uintptr(header_size);
if padding < needed_space {