From 580548f44f3e2dbfd4e655f869ad654261c9e29d Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 29 Mar 2019 14:21:50 -0700 Subject: [PATCH] context_get_arena --- 4coder_default_framework.cpp | 10 +- 4coder_generated/app_functions.h | 7 + 4coder_mirror.cpp | 254 +++++++++++++++---------------- 4ed.cpp | 3 + 4ed_api_implementation.cpp | 6 + 4ed_app_models.h | 4 + 4ed_history.cpp | 38 ++--- 7 files changed, 171 insertions(+), 151 deletions(-) diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index fb87bc86..6b63c7ec 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -179,8 +179,8 @@ get_next_view_after_active(Application_Links *app, u32 access){ static void view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){ if (count > 0){ - // TODO(allen): replace with context supplied arena - Arena arena = make_arena(app); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); struct View_Node{ View_Node *next; @@ -200,7 +200,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 View_Node *primary_view_last = 0; i32 available_view_count = 0; - primary_view_first = primary_view_last = push_array(&arena, View_Node, 1); + primary_view_first = primary_view_last = push_array(arena, View_Node, 1); primary_view_last->next = 0; primary_view_last->view_id = view_id; available_view_count += 1; @@ -209,7 +209,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 if (view_id == first_view_id){ break; } - View_Node *node = push_array(&arena, View_Node, 1); + View_Node *node = push_array(arena, View_Node, 1); primary_view_last->next = node; node->next = 0; node->view_id = view_id; @@ -225,7 +225,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 } } - arena_release_all(&arena); + end_temp_memory(temp); } } diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 675e13b1..51055f62 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -1,6 +1,7 @@ struct Application_Links; #define GLOBAL_SET_SETTING_SIG(n) b32 n(Application_Links *app, Global_Setting_ID setting, i32 value) #define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size) +#define CONTEXT_GET_ARENA_SIG(n) Arena* n(Application_Links *app) #define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out) #define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags) #define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out) @@ -158,6 +159,7 @@ struct Application_Links; #define GET_VIEW_VISIBLE_RANGE_SIG(n) Range n(Application_Links *app, View_ID view_id) typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function); typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function); +typedef CONTEXT_GET_ARENA_SIG(Context_Get_Arena_Function); typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function); typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function); typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function); @@ -317,6 +319,7 @@ struct Application_Links{ #if defined(ALLOW_DEP_4CODER) Global_Set_Setting_Function *global_set_setting; Global_Set_Mapping_Function *global_set_mapping; +Context_Get_Arena_Function *context_get_arena; Create_Child_Process_Function *create_child_process; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process; @@ -475,6 +478,7 @@ Get_View_Visible_Range_Function *get_view_visible_range; #else Global_Set_Setting_Function *global_set_setting_; Global_Set_Mapping_Function *global_set_mapping_; +Context_Get_Arena_Function *context_get_arena_; Create_Child_Process_Function *create_child_process_; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_; @@ -641,6 +645,7 @@ int32_t type_coroutine; #define FillAppLinksAPI(app_links) do{\ app_links->global_set_setting_ = Global_Set_Setting;\ app_links->global_set_mapping_ = Global_Set_Mapping;\ +app_links->context_get_arena_ = Context_Get_Arena;\ app_links->create_child_process_ = Create_Child_Process;\ app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\ app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\ @@ -799,6 +804,7 @@ app_links->get_view_visible_range_ = Get_View_Visible_Range;} while(false) #if defined(ALLOW_DEP_4CODER) static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting(app, setting, value));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping(app, data, size));} +static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena(app));} static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer(app, child_process_id, buffer_id, flags));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process(app, buffer_id, child_process_id_out));} @@ -957,6 +963,7 @@ static Range get_view_visible_range(Application_Links *app, View_ID view_id){ret #else static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));} +static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena_(app));} static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process_(app, buffer_id, child_process_id_out));} diff --git a/4coder_mirror.cpp b/4coder_mirror.cpp index bf195502..06500b26 100644 --- a/4coder_mirror.cpp +++ b/4coder_mirror.cpp @@ -262,116 +262,115 @@ mirror_add_range__inner_check_optimization(Application_Links *app, Managed_Objec if (get_buffer_summary(app, source, AccessAll, &source_buffer)){ Managed_Scope scope = managed_object_get_containing_scope(app, mirror); Managed_Object mirror_check = mirror__check_scope_for_mirror(app, scope); - if (mirror_check == mirror){ - Mirror mirror_data = {}; - if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){ - Buffer_Summary mirror_buffer = {}; - Buffer_ID mirror_id = mirror_data.mirror_buffer_id; - if (get_buffer_summary(app, mirror_id, AccessAll, &mirror_buffer)){ - Arena arena = make_arena(app, (8 << 10)); - - // read mirror data into hot structure - Mirror_Hot mirror_hot = {}; - mirror_hot.count = mirror_data.count; - mirror_hot.source_buffer_ids = push_array(&arena, Buffer_ID, mirror_hot.count); - mirror_hot.mirror_ranges = push_array(&arena, Marker, (mirror_hot.count)*2); - mirror_hot.source_ranges = push_array(&arena, Managed_Object, mirror_hot.count); - - b32 load_success = false; - if (mirror_hot.count == 0){ - load_success = true; - } - else{ - load_success = (managed_object_load_data(app, mirror_data.source_buffer_ids, 0, mirror_hot.count , mirror_hot.source_buffer_ids) && - managed_object_load_data(app, mirror_data.mirror_ranges , 0, mirror_hot.count*2, mirror_hot.mirror_ranges ) && - managed_object_load_data(app, mirror_data.source_ranges , 0, mirror_hot.count , mirror_hot.source_ranges )); - } - - if (load_success){ - Mirror__Check_Range_Result check = mirror__check_range_to_add(app, &arena, mirror_first, source_first, length, - &source_buffer, &mirror_buffer, &mirror_hot, - collidable_indices_first, auto_trust_text); - - if (check.passed_checks){ - // insert the new range at the insert index - b32 r = true; - i32 insert_index = check.insert_index; - *insert_index_out = insert_index; - - Marker mirror_range[2] = {}; - mirror_range[0].pos = mirror_first; - mirror_range[0].lean_right = false; - mirror_range[1].pos = mirror_first + length; - mirror_range[1].lean_right = true; - - Marker source_range[2] = {}; - source_range[0].pos = source_first; - source_range[0].lean_right = false; - source_range[1].pos = source_first + length; - source_range[1].lean_right = true; - - Managed_Scope scopes[3] = {}; - scopes[0] = scope; - scopes[1] = mirror_data.mirror_scope; - buffer_get_managed_scope(app, source, &scopes[2]); - - Managed_Scope source_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 3); - - Managed_Object new_source_range = alloc_buffer_markers_on_buffer(app, source, 2, &source_sub_scope); - r = r && managed_object_store_data(app, new_source_range, 0, 2, &source_range); - - if (mirror_data.count + 1 > mirror_data.max){ - if (mirror_data.count != 0){ - r = r && managed_object_free(app, mirror_data.source_buffer_ids); - r = r && managed_object_free(app, mirror_data.mirror_ranges); - r = r && managed_object_free(app, mirror_data.source_ranges); - } - - Managed_Scope mirror_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 2); - i32 new_max = 256; - if (new_max <= mirror_data.max){ - new_max = mirror_data.max*2; - } - mirror_data.source_buffer_ids = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Buffer_ID), new_max); - mirror_data.mirror_ranges = alloc_buffer_markers_on_buffer(app, mirror_id, new_max*2, &mirror_sub_scope); - mirror_data.source_ranges = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Managed_Object), new_max); - - mirror_data.max = new_max; - - // head ranges - i32 head_count = insert_index; - if (head_count > 0){ - r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, 0, head_count , mirror_hot.source_buffer_ids); - r = r && managed_object_store_data(app, mirror_data.mirror_ranges , 0, head_count*2, mirror_hot.mirror_ranges ); - r = r && managed_object_store_data(app, mirror_data.source_ranges , 0, head_count , mirror_hot.source_ranges ); - } - } - - // tail ranges - i32 tail_count = mirror_hot.count - insert_index; - if (tail_count > 0){ - i32 to = insert_index + 1; - i32 from = insert_index; - r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, to , tail_count , mirror_hot.source_buffer_ids + from); - r = r && managed_object_store_data(app, mirror_data.mirror_ranges , to*2, tail_count*2, mirror_hot.mirror_ranges + from*2 ); - r = r && managed_object_store_data(app, mirror_data.source_ranges , to , tail_count , mirror_hot.source_ranges + from ); - } - - // new range - r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, insert_index , 1, &source ); - r = r && managed_object_store_data(app, mirror_data.mirror_ranges , insert_index*2, 2, mirror_range ); - r = r && managed_object_store_data(app, mirror_data.source_ranges , insert_index , 1, &new_source_range); - - mirror_data.count += 1; - - managed_object_store_data(app, mirror, 0, 1, &mirror_data); - - result = r; - } - } - - arena_release_all(&arena); + Mirror mirror_data = {}; + if (mirror_check == mirror && managed_object_load_data(app, mirror, 0, 1, &mirror_data)){ + Buffer_Summary mirror_buffer = {}; + Buffer_ID mirror_id = mirror_data.mirror_buffer_id; + if (get_buffer_summary(app, mirror_id, AccessAll, &mirror_buffer)){ + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); + + // read mirror data into hot structure + Mirror_Hot mirror_hot = {}; + mirror_hot.count = mirror_data.count; + mirror_hot.source_buffer_ids = push_array(arena, Buffer_ID, mirror_hot.count); + mirror_hot.mirror_ranges = push_array(arena, Marker, (mirror_hot.count)*2); + mirror_hot.source_ranges = push_array(arena, Managed_Object, mirror_hot.count); + + b32 load_success = false; + if (mirror_hot.count == 0){ + load_success = true; } + else{ + load_success = (managed_object_load_data(app, mirror_data.source_buffer_ids, 0, mirror_hot.count , mirror_hot.source_buffer_ids) && + managed_object_load_data(app, mirror_data.mirror_ranges , 0, mirror_hot.count*2, mirror_hot.mirror_ranges ) && + managed_object_load_data(app, mirror_data.source_ranges , 0, mirror_hot.count , mirror_hot.source_ranges )); + } + + if (load_success){ + Mirror__Check_Range_Result check = mirror__check_range_to_add(app, arena, mirror_first, source_first, length, + &source_buffer, &mirror_buffer, &mirror_hot, + collidable_indices_first, auto_trust_text); + + if (check.passed_checks){ + // insert the new range at the insert index + b32 r = true; + i32 insert_index = check.insert_index; + *insert_index_out = insert_index; + + Marker mirror_range[2] = {}; + mirror_range[0].pos = mirror_first; + mirror_range[0].lean_right = false; + mirror_range[1].pos = mirror_first + length; + mirror_range[1].lean_right = true; + + Marker source_range[2] = {}; + source_range[0].pos = source_first; + source_range[0].lean_right = false; + source_range[1].pos = source_first + length; + source_range[1].lean_right = true; + + Managed_Scope scopes[3] = {}; + scopes[0] = scope; + scopes[1] = mirror_data.mirror_scope; + buffer_get_managed_scope(app, source, &scopes[2]); + + Managed_Scope source_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 3); + + Managed_Object new_source_range = alloc_buffer_markers_on_buffer(app, source, 2, &source_sub_scope); + r = r && managed_object_store_data(app, new_source_range, 0, 2, &source_range); + + if (mirror_data.count + 1 > mirror_data.max){ + if (mirror_data.count != 0){ + r = r && managed_object_free(app, mirror_data.source_buffer_ids); + r = r && managed_object_free(app, mirror_data.mirror_ranges); + r = r && managed_object_free(app, mirror_data.source_ranges); + } + + Managed_Scope mirror_sub_scope = get_managed_scope_with_multiple_dependencies(app, scopes, 2); + i32 new_max = 256; + if (new_max <= mirror_data.max){ + new_max = mirror_data.max*2; + } + mirror_data.source_buffer_ids = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Buffer_ID), new_max); + mirror_data.mirror_ranges = alloc_buffer_markers_on_buffer(app, mirror_id, new_max*2, &mirror_sub_scope); + mirror_data.source_ranges = alloc_managed_memory_in_scope(app, mirror_sub_scope, sizeof(Managed_Object), new_max); + + mirror_data.max = new_max; + + // head ranges + i32 head_count = insert_index; + if (head_count > 0){ + r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, 0, head_count , mirror_hot.source_buffer_ids); + r = r && managed_object_store_data(app, mirror_data.mirror_ranges , 0, head_count*2, mirror_hot.mirror_ranges ); + r = r && managed_object_store_data(app, mirror_data.source_ranges , 0, head_count , mirror_hot.source_ranges ); + } + } + + // tail ranges + i32 tail_count = mirror_hot.count - insert_index; + if (tail_count > 0){ + i32 to = insert_index + 1; + i32 from = insert_index; + r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, to , tail_count , mirror_hot.source_buffer_ids + from); + r = r && managed_object_store_data(app, mirror_data.mirror_ranges , to*2, tail_count*2, mirror_hot.mirror_ranges + from*2 ); + r = r && managed_object_store_data(app, mirror_data.source_ranges , to , tail_count , mirror_hot.source_ranges + from ); + } + + // new range + r = r && managed_object_store_data(app, mirror_data.source_buffer_ids, insert_index , 1, &source ); + r = r && managed_object_store_data(app, mirror_data.mirror_ranges , insert_index*2, 2, mirror_range ); + r = r && managed_object_store_data(app, mirror_data.source_ranges , insert_index , 1, &new_source_range); + + mirror_data.count += 1; + + managed_object_store_data(app, mirror, 0, 1, &mirror_data); + + result = r; + } + } + + end_temp_memory(temp); } } } @@ -553,9 +552,10 @@ static i32 mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_ID source, i32 mirror_first, i32 source_first, i32 max_length){ i32 result = 0; - Arena arena = make_arena(app, (8 << 10)); - char *buffer_1 = push_array(&arena, char, max_length); - char *buffer_2 = push_array(&arena, char, max_length); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); + char *buffer_1 = push_array(arena, char, max_length); + char *buffer_2 = push_array(arena, char, max_length); if (buffer_read_range(app, source, source_first, source_first + max_length, buffer_1)){ if (buffer_read_range(app, mirror, mirror_first, mirror_first + max_length, buffer_2)){ for (; result < max_length; @@ -566,7 +566,7 @@ mirror__range_loose_get_length(Application_Links *app, Buffer_ID mirror, Buffer_ } } } - arena_release_all(&arena); + end_temp_memory(temp); return(result); } @@ -597,18 +597,16 @@ mirror_buffer_insert_range(Application_Links *app, Buffer_ID mirror, Buffer_ID s if (mode == MirrorMode_Constructing){ b32 did_insert = false; { - // TODO(casey): Allen, this is going to be suuuuuper slow - it has to do a whole memory block - // reserve just to get the temporary space. This is the kind of thing that would be super simple and - // very efficient with a stack off the app pointer. - Arena arena = make_arena(app, (8 << 10)); - char *buffer = push_array(&arena, char, length); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); + char *buffer = push_array(arena, char, length); if (buffer_read_range(app, source, source_first, source_first + length, buffer)){ String string = make_string(buffer, length); if (buffer_replace_range(app, mirror, mirror_insert_pos, mirror_insert_pos, string)){ did_insert = true; } } - arena_release_all(&arena); + end_temp_memory(temp); } if (did_insert){ result = mirror_add_range__inner(app, mirror_object, source, mirror_insert_pos, source_first, length); @@ -798,20 +796,21 @@ mirror_buffer_insert_range_array(Application_Links *app, Buffer_ID mirror, Mirro Mirror_Range *range = ranges; i32 safe_to_ignore_index = 0; i32 total_shift = 0; - Arena arena = make_arena(app, (8 << 10)); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); for (i32 i = 0; i < count; i += 1, range += 1){ i32 mirror_first = range->mirror_first + total_shift; b32 did_insert = false; { - Temp_Memory_Arena temp = begin_temp_memory(&arena); - char *buffer = push_array(&arena, char, range->length); + Temp_Memory_Arena buffer_temp = begin_temp_memory(arena); + char *buffer = push_array(arena, char, range->length); if (buffer_read_range(app, range->source_buffer_id, range->source_first, range->source_first + range->length, buffer)){ String string = make_string(buffer, range->length); if (buffer_replace_range(app, mirror, mirror_first, mirror_first, string)){ did_insert = true; } } - end_temp_memory(temp); + end_temp_memory(buffer_temp); } i32 new_range_index = 0; if (range->length > 0){ @@ -826,7 +825,7 @@ mirror_buffer_insert_range_array(Application_Links *app, Buffer_ID mirror, Mirro } total_shift += range->length; } - arena_release_all(&arena); + end_temp_memory(temp); result = r; } } @@ -849,9 +848,10 @@ mirror_edit_handler(Application_Links *app, Buffer_ID buffer_id, i32 first, i32 if (mirror_get_mode__inner(app, mirror, &mode)){ Mirror mirror_data = {}; if (managed_object_load_data(app, mirror, 0, 1, &mirror_data)){ - Arena arena = make_arena(app, (8 << 10)); + Arena *arena = context_get_arena(app); + Temp_Memory_Arena temp = begin_temp_memory(arena); - Mirror_Hot mirror_hot = mirror__hot_from_data(app, &arena, mirror_data); + Mirror_Hot mirror_hot = mirror__hot_from_data(app, arena, mirror_data); switch (mode){ case MirrorMode_Constructing: { @@ -944,7 +944,7 @@ mirror_edit_handler(Application_Links *app, Buffer_ID buffer_id, i32 first, i32 }break; } - arena_release_all(&arena); + end_temp_memory(temp); } } } diff --git a/4ed.cpp b/4ed.cpp index a6d208b7..b7eede6c 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -946,6 +946,9 @@ App_Init_Sig(app_init){ // NOTE(allen): init GUI keys models->user_up_key = key_up; models->user_down_key = key_down; + + // NOTE(allen): + models->custom_layer_arena = make_arena(&models->app_links); } App_Step_Sig(app_step){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index cffb60f5..cd84f432 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -190,6 +190,12 @@ DOC(Dumps away the previous mappings and instantiates the mappings described in return(result); } +API_EXPORT Arena* +Context_Get_Arena(Application_Links *app){ + Models *models = (Models*)app->cmd_context; + return(&models->custom_layer_arena); +} + API_EXPORT b32 Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){ Models *models = (Models*)app->cmd_context; diff --git a/4ed_app_models.h b/4ed_app_models.h index 9e858c28..6b503ecf 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -29,6 +29,7 @@ struct App_Settings{ struct Models{ Mem_Options mem; + App_Settings settings; Face_ID global_font_id; @@ -81,6 +82,7 @@ struct Models{ b32 keep_playing; + // TODO(allen): do(eliminate user_*_key* nonsense from the core) Key_Code user_up_key; Key_Code user_down_key; Key_Modifier user_up_key_modifier; @@ -98,6 +100,8 @@ struct Models{ b32 animate_next_frame; + Arena custom_layer_arena; + // Last frame state Vec2_i32 prev_p; Panel *prev_mouse_panel; diff --git a/4ed_history.cpp b/4ed_history.cpp index 1a466c92..8ad8f0ad 100644 --- a/4ed_history.cpp +++ b/4ed_history.cpp @@ -144,33 +144,32 @@ history_is_activated(History *history){ internal void history_free(Heap *heap, History *history){ - if (!history->activated){ - return; + if (history->activated){ + arena_release_all(&history->arena); + memory_bank_free_all(heap, &history->bank); + block_zero_struct(history); } - arena_release_all(&history->arena); - memory_bank_free_all(heap, &history->bank); - block_zero_struct(history); } internal i32 history_get_record_count(History *history){ - if (!history->activated){ - return(0); + i32 result = 0; + if (history->activated){ + result = history->record_count; } - return(history->record_count); + return(result); } internal Record* history_get_record(History *history, i32 index){ - if (!history->activated){ - return(0); + Record *result = 0; + if (history->activated){ + Node *node = history__to_node(history, index); + if (node != 0){ + result = CastFromMember(Record, node, node); + } } - Record *record = 0; - Node *node = history__to_node(history, index); - if (node != 0){ - record = CastFromMember(Record, node, node); - } - return(record); + return(result); } internal Record* @@ -189,10 +188,11 @@ history_get_sub_record(Record *record, i32 sub_index){ internal Record* history_get_dummy_record(History *history){ - if (!history->activated){ - return(0); + Record *result = 0; + if (history->activated){ + result = CastFromMember(Record, node, &history->records); } - return(CastFromMember(Record, node, &history->records)); + return(result); } internal void