Remove Allocator stuff

This commit is contained in:
Krzosa Karol
2022-10-10 10:22:04 +02:00
parent 2f153a7cd3
commit 7aa0ba56b6
14 changed files with 69 additions and 192 deletions

View File

@@ -3,11 +3,11 @@
// a copy of which can be found in the LICENSE file.
#include <string.h>
#define Set_BigInt_Allocator(x) BigInt_Allocator bigint_allocator(x)
struct BigInt_Allocator{
Allocator *old;
BigInt_Allocator(Allocator *allocator){old = bigint_allocator; bigint_allocator = allocator;}
~BigInt_Allocator(){bigint_allocator = old;}
#define Set_BigInt_Arena(x) BigInt_Arena bigint_allocator(x)
struct BigInt_Arena{
Arena *old;
BigInt_Arena(Arena *allocator){old = bigint_allocator; bigint_allocator = allocator;}
~BigInt_Arena(){bigint_allocator = old;}
};
function BigInt
@@ -39,7 +39,7 @@ bigint_add(const BigInt *a, const BigInt *b){
}
function BigInt
bigint_copy(Allocator *allocator, BigInt *src){
bigint_copy(Arena *allocator, BigInt *src){
BigInt dest = {};
if (src->digit_count == 0){
bigint_init_unsigned(&dest, 0);
@@ -55,7 +55,7 @@ bigint_copy(Allocator *allocator, BigInt *src){
dest.digit_count = src->digit_count;
count_bigint_alloc();
dest.digits = exp_alloc_array(allocator, uint64_t, dest.digit_count, AF_ZeroMemory);
dest.digits = arena_push_array(allocator, uint64_t, dest.digit_count, AF_ZeroMemory);
memcpy(dest.digits, src->digits, sizeof(uint64_t) * dest.digit_count);
return dest;
}
@@ -1925,9 +1925,9 @@ void bigint_print(BigInt *bigint, uint64_t base)
}
}
const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, uint64_t base)
const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint64_t base)
{
Set_BigInt_Allocator(allocator);
Set_BigInt_Arena(allocator);
if (bigint->digit_count == 0)
{
return "0";
@@ -1948,7 +1948,7 @@ const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, u
return res;
}
size_t len = bigint->digit_count * 64;
char *start = (char *)exp_alloc(allocator, len);
char *start = (char *)arena_push_size(allocator, len);
char *buf = start;
BigInt digit_bi = { 0 };
@@ -1980,7 +1980,7 @@ const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, u
}
// reverse
char *out = (char *)exp_alloc(allocator, buf - start + 2);
char *out = (char *)arena_push_size(allocator, buf - start + 2);
char *current = out;
if (bigint->is_negative)
{