prepping to collapse Arena receiving functions to those that receive AllocatorInfo

perf impact of the indirection should be minimal, reduces code duplication.

Ideally we'd use gencpp to just have the user specify what they want, then modify which proc is avail by doing the refactors required for using either
However, it can't process execution bodies yet or expressions so thats not possible.

The other way is to just utilize _Generic to generalize the codepath so that it collapses neater but that leads to a ton of implementation getting lifted to preprocessing... so no.
This commit is contained in:
ed
2025-02-09 11:51:50 -05:00
parent e4f797f594
commit c8cb9f3995
13 changed files with 268 additions and 63 deletions
+9 -4
View File
@@ -68,10 +68,15 @@ struct TempArena
MD_API void* arena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags);
force_inline AllocatorInfo
arena_allocator(Arena* arena) {
AllocatorInfo info = { arena_allocator_proc, arena};
return info;
force_inline AllocatorInfo arena_allocator(Arena* arena) { AllocatorInfo info = { arena_allocator_proc, arena}; return info; }
// Useful for providing an arena to scratch_begin_alloc
force_inline Arena*
extract_arena(AllocatorInfo ainfo) {
if (allocator_type(ainfo) == AllocatorType_Arena) {
return (Arena*) ainfo.data;
}
return nullptr;
}
//- rjf: arena creation/destruction
-2
View File
@@ -19,7 +19,6 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char**
#endif
thread_namef("[main thread]");
// TODO(Ed): Review?
TempArena scratch = scratch_begin(0, 0);
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments);
@@ -41,7 +40,6 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char**
void
supplement_thread_base_entry_point(SupplementThread_EntryPointProc* entry_point, void* params)
{
// TODO(Ed): Review?
TCTX tctx;
tctx_init_and_equip(&tctx);
entry_point(params);
-1
View File
@@ -49,7 +49,6 @@ log_msgf(LogMsgKind kind, char *fmt, ...) {
}
}
////////////////////////////////
//~ rjf: Log Scopes
+14 -16
View File
@@ -1444,22 +1444,20 @@ alloc_file_name_date_time_string(AllocatorInfo ainfo, DateTime* date_time) {
String8
string_from_elapsed_time_alloc(AllocatorInfo ainfo, DateTime dt) {
U8 bytes[KB(8)];
FArena arena = farena_from_memory(bytes, size_of(bytes));
AllocatorInfo scratch = farena_allocator(arena);
TempArena scratch = scratch_begin_alloc(ainfo);
String8List list = {0};
if (dt.year) {
str8_list_allocf(scratch, &list, "%dy", dt.year);
str8_list_allocf(scratch, &list, "%um", dt.mon);
str8_list_allocf(scratch, &list, "%ud", dt.day);
str8_list_pushf(scratch.arena, &list, "%dy", dt.year);
str8_list_pushf(scratch.arena, &list, "%um", dt.mon);
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
} else if (dt.mon) {
str8_list_allocf(scratch, &list, "%um", dt.mon);
str8_list_allocf(scratch, &list, "%ud", dt.day);
str8_list_pushf(scratch.arena, &list, "%um", dt.mon);
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
} else if (dt.day) {
str8_list_allocf(scratch, &list, "%ud", dt.day);
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
}
str8_list_allocf(scratch, &list, "%u:%u:%u:%u ms", dt.hour, dt.min, dt.sec, dt.msec);
str8_list_pushf(scratch.arena, &list, "%u:%u:%u:%u ms", dt.hour, dt.min, dt.sec, dt.msec);
StringJoin join = { str8_lit_comp(""), str8_lit_comp(" "), str8_lit_comp("") };
String8 result = str8_list_join_alloc(ainfo, &list, &join);
@@ -1520,7 +1518,7 @@ try_guid_from_string(String8 string, Guid *guid_out)
String8
indented_from_string(Arena* arena, String8 string)
{
#if 1 // Better than enforcing abstract allocator for this case.
#if MD_DONT_MAP_ANREA_TO_ALLOCATOR_IMPL
TempArena scratch = scratch_begin(&arena, 1);
read_only local_persist U8 indentation_bytes[] = " ";
@@ -1560,7 +1558,7 @@ indented_from_string(Arena* arena, String8 string)
String8
indented_from_string_alloc(AllocatorInfo ainfo, String8 string)
{
TempArena scratch = scratch_begin(0, 0);
TempArena scratch = scratch_begin_alloc(ainfo);
read_only local_persist U8 indentation_bytes[] = " ";
String8List indented_strings = {0};
@@ -1600,7 +1598,7 @@ indented_from_string_alloc(AllocatorInfo ainfo, String8 string)
String8
escaped_from_raw_str8(Arena* arena, String8 string)
{
#if 1 // Better than enforcing abstract allocator for this case.
#if MD_DONT_MAP_ANREA_TO_ALLOCATOR_IMPL
TempArena scratch = scratch_begin(&arena, 1);
String8List parts = {0};
@@ -1650,7 +1648,7 @@ escaped_from_raw_str8(Arena* arena, String8 string)
String8
escaped_from_raw_str8_alloc(AllocatorInfo ainfo, String8 string)
{
TempArena scratch = scratch_begin(0, 0);
TempArena scratch = scratch_begin_alloc(ainfo);
String8List parts = {0};
U64 start_split_idx = 0;
@@ -1747,7 +1745,7 @@ raw_from_escaped_str8(Arena* arena, String8 string)
String8
raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string)
{
TempArena scratch = scratch_begin(0, 0);
TempArena scratch = scratch_begin_alloc(ainfo);
String8List strs = {0};
U64 start = 0;
@@ -2003,7 +2001,7 @@ fuzzy_match_find(Arena *arena, String8 needle, String8 haystack)
FuzzyMatchRangeList
fuzzy_match_find_alloc(AllocatorInfo ainfo, String8 needle, String8 haystack)
{
TempArena scratch = scratch_begin(0, 0);
TempArena scratch = scratch_begin_alloc(ainfo);
String8List needles = str8_split(scratch.arena, needle, (U8*)" ", 1, 0);
FuzzyMatchRangeList
result = {0};
+8
View File
@@ -39,6 +39,14 @@ void tctx_write_srcloc(char* file_name, U64 line_number);
void tctx_read_srcloc (char** file_name, U64* line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
inline TempArena
scratch__begin_alloc(AllocatorInfo ainfo) {
Arena* arena = extract_arena(ainfo);
TempArena scratch = temp_begin(tctx_get_scratch(arena, arena != nullptr));
return scratch;
}
#define scratch_begin_alloc(ainfo) scratch__begin_alloc(ainfo)
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
#define scratch_end(scratch) temp_end(scratch)