Growable arena in custom layer built on top of the size-fixed partition system
parent
5926d9fdd9
commit
74405dd8fe
|
@ -72,7 +72,7 @@ config_stringize_errors(Partition *arena, Config *parsed){
|
|||
String result = {};
|
||||
if (parsed->errors.first != 0){
|
||||
result.str = push_array(arena, char, 0);
|
||||
result.memory_size = partition_remaining(arena);
|
||||
result.memory_size = part_remaining(arena);
|
||||
for (Config_Error *error = parsed->errors.first;
|
||||
error != 0;
|
||||
error = error->next){
|
||||
|
@ -1623,7 +1623,7 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c
|
|||
|
||||
// Values
|
||||
Temp_Memory temp2 = begin_temp_memory(scratch);
|
||||
String space = string_push(scratch, partition_remaining(scratch));
|
||||
String space = string_push(scratch, part_remaining(scratch));
|
||||
|
||||
{
|
||||
config_feedback_string(&space, "user_name", config->user_name);
|
||||
|
|
|
@ -448,7 +448,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in
|
|||
String replace_string = with.string;
|
||||
|
||||
Buffer_Edit *edits = (Buffer_Edit*)partition_current(part);
|
||||
int32_t edit_max = (partition_remaining(part))/sizeof(Buffer_Edit);
|
||||
int32_t edit_max = (part_remaining(part))/sizeof(Buffer_Edit);
|
||||
int32_t edit_count = 0;
|
||||
|
||||
if (edit_max >= 1){
|
||||
|
@ -592,7 +592,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
|
|||
Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate);
|
||||
|
||||
char *string_base = (char*)partition_current(part);
|
||||
String string = make_string(string_base, 0, partition_remaining(part));
|
||||
String string = make_string(string_base, 0, part_remaining(part));
|
||||
|
||||
closed_correctly = false;
|
||||
still_looping = false;
|
||||
|
|
|
@ -36,7 +36,7 @@ buffered_write_stream_write(Application_Links *app, Buffered_Write_Stream *strea
|
|||
text.size = 0;
|
||||
}
|
||||
else{
|
||||
int32_t partial_size = partition_remaining(stream->buffering_arena);
|
||||
int32_t partial_size = part_remaining(stream->buffering_arena);
|
||||
buffered = push_array(stream->buffering_arena, char, partial_size);
|
||||
Assert(partial_size < text.size);
|
||||
memcpy(buffered, text.str, partial_size);
|
||||
|
|
|
@ -262,7 +262,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
|
|||
{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1060 },
|
||||
{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 203 },
|
||||
{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 484 },
|
||||
{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 981 },
|
||||
{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 977 },
|
||||
{ PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 135 },
|
||||
{ PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 159 },
|
||||
{ PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 26 },
|
||||
|
@ -305,11 +305,11 @@ static Command_Metadata fcoder_metacmd_table[220] = {
|
|||
{ PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 79 },
|
||||
{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 562 },
|
||||
{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 540 },
|
||||
{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 784 },
|
||||
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 894 },
|
||||
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 926 },
|
||||
{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 856 },
|
||||
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 765 },
|
||||
{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 780 },
|
||||
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 890 },
|
||||
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 922 },
|
||||
{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 852 },
|
||||
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 761 },
|
||||
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1557 },
|
||||
{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 133 },
|
||||
{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 330 },
|
||||
|
@ -362,7 +362,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
|
|||
{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 573 },
|
||||
{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1067 },
|
||||
{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1074 },
|
||||
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 28, 942 },
|
||||
{ PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder theme selector list.", 37, "w:\\4ed\\code\\4coder_lists.cpp", 28, 938 },
|
||||
{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1464 },
|
||||
{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1619 },
|
||||
{ PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 55 },
|
||||
|
|
|
@ -1309,6 +1309,20 @@ build_string(Partition *part, String s0, String s1, String s2){
|
|||
return(sr);
|
||||
}
|
||||
|
||||
static String
|
||||
string_push_copy(Arena *arena, String str){
|
||||
String result = {};
|
||||
if (str.str != 0){
|
||||
result.str = push_array(arena, char, str.size + 1);
|
||||
if (result.str != 0){
|
||||
result.memory_size = str.size + 1;
|
||||
copy(&result, str);
|
||||
result.str[result.size] = 0;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
static bool32
|
||||
lexer_keywords_default_init(Partition *arena, Cpp_Keyword_Table *kw_out, Cpp_Keyword_Table *pp_out){
|
||||
bool32 success = false;
|
||||
|
@ -1327,18 +1341,27 @@ lexer_keywords_default_init(Partition *arena, Cpp_Keyword_Table *kw_out, Cpp_Key
|
|||
////////////////////////////////
|
||||
|
||||
static String
|
||||
get_hot_directory(Application_Links *app, Partition *arena){
|
||||
Temp_Memory temp = begin_temp_memory(arena);
|
||||
int32_t space_cap = partition_remaining(arena);
|
||||
char *space = push_array(arena, char, space_cap);
|
||||
get_hot_directory(Application_Links *app, Partition *part){
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
int32_t space_cap = part_remaining(part);
|
||||
char *space = push_array(part, char, space_cap);
|
||||
String hot_dir = make_string_cap(space, 0, space_cap);
|
||||
hot_dir.size = directory_get_hot(app, hot_dir.str, hot_dir.memory_size);
|
||||
end_temp_memory(temp);
|
||||
push_array(arena, char, hot_dir.size);
|
||||
push_array(part, char, hot_dir.size);
|
||||
hot_dir.memory_size = hot_dir.size;
|
||||
return(hot_dir);
|
||||
}
|
||||
|
||||
static String
|
||||
get_hot_directory(Application_Links *app, Arena *arena){
|
||||
int32_t space_required = directory_get_hot(app, 0, 0);
|
||||
char *space = push_array(arena, char, space_required);
|
||||
String hot_dir = make_string_cap(space, 0, space_required);
|
||||
hot_dir.size = directory_get_hot(app, hot_dir.str, hot_dir.memory_size);
|
||||
return(hot_dir);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
static String
|
||||
|
|
|
@ -11,15 +11,15 @@ distribute, and modify this file as you see fit.
|
|||
|
||||
static Partition
|
||||
make_part(void *memory, i32_4tech size){
|
||||
Partition partition = {};
|
||||
partition.base = (char*)memory;
|
||||
partition.pos = 0;
|
||||
partition.max = size;
|
||||
return partition;
|
||||
Partition part = {};
|
||||
part.base = (char*)memory;
|
||||
part.pos = 0;
|
||||
part.max = size;
|
||||
return(part);
|
||||
}
|
||||
|
||||
static void*
|
||||
partition_allocate(Partition *data, i32_4tech size){
|
||||
part_allocate(Partition *data, i32_4tech size){
|
||||
void *ret = 0;
|
||||
if (size < 0){
|
||||
size = 0;
|
||||
|
@ -32,55 +32,226 @@ partition_allocate(Partition *data, i32_4tech size){
|
|||
}
|
||||
|
||||
static void
|
||||
partition_reduce(Partition *data, i32_4tech size){
|
||||
part_reduce(Partition *data, i32_4tech size){
|
||||
if (size > 0 && size <= data->pos){
|
||||
data->pos -= size;
|
||||
}
|
||||
}
|
||||
|
||||
static void*
|
||||
partition_align(Partition *data, u32_4tech boundary){
|
||||
--boundary;
|
||||
data->pos = (data->pos + boundary) & (~boundary);
|
||||
return(data->base + data->pos);
|
||||
static void
|
||||
part_align(Partition *data, i32_4tech boundary){
|
||||
i32_4tech p = data->pos;
|
||||
p += boundary - 1;
|
||||
data->pos = p - p%boundary;
|
||||
}
|
||||
|
||||
static void*
|
||||
partition_current(Partition *data){
|
||||
part_current(Partition *data){
|
||||
return(data->base + data->pos);
|
||||
}
|
||||
|
||||
static i32_4tech
|
||||
partition_remaining(Partition *data){
|
||||
part_remaining(Partition *data){
|
||||
return(data->max - data->pos);
|
||||
}
|
||||
|
||||
static Partition
|
||||
partition_sub_part(Partition *data, i32_4tech size){
|
||||
part_sub_part(Partition *data, i32_4tech size){
|
||||
Partition result = {};
|
||||
void *d = partition_allocate(data, size);
|
||||
void *d = part_allocate(data, size);
|
||||
if (d != 0){
|
||||
result = make_part(d, size);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define push_array(part, T, size) (T*)partition_allocate(part, sizeof(T)*(size))
|
||||
#define push_align(part, b) partition_align(part, b)
|
||||
|
||||
static Temp_Memory
|
||||
begin_temp_memory(Partition *data){
|
||||
Temp_Memory result;
|
||||
result.handle = data;
|
||||
Temp_Memory result = {};
|
||||
result.part = data;
|
||||
result.pos = data->pos;
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
end_temp_memory(Temp_Memory temp){
|
||||
((Partition*)temp.handle)->pos = temp.pos;
|
||||
temp.part->pos = temp.pos;
|
||||
}
|
||||
|
||||
static void*
|
||||
push_allocator_allocate(Partition *part, i32_4tech size){
|
||||
return(part_allocate(part, size));
|
||||
}
|
||||
|
||||
static void
|
||||
push_allocator_align(Partition *part, i32_4tech b){
|
||||
part_align(part, b);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#if defined(FCODER_CUSTOM_H)
|
||||
|
||||
static Arena
|
||||
make_arena(Application_Links *app, i32_4tech chunk_size, i32_4tech initial_align){
|
||||
Arena arena = {};
|
||||
arena.app = app;
|
||||
arena.chunk_size = chunk_size;
|
||||
arena.align = initial_align;
|
||||
return(arena);
|
||||
}
|
||||
|
||||
static Arena
|
||||
make_arena(Application_Links *app, i32_4tech chunk_size){
|
||||
return(make_arena(app, chunk_size, 1));
|
||||
}
|
||||
|
||||
static Arena
|
||||
make_arena(Application_Links *app){
|
||||
return(make_arena(app, 4096, 1));
|
||||
}
|
||||
|
||||
static void
|
||||
arena_release_all(Arena *arena){
|
||||
Application_Links *app = arena->app;
|
||||
for (Partition_Chained *part = arena->part, *prev = 0;
|
||||
part != 0;
|
||||
part = prev){
|
||||
prev = part->prev;
|
||||
memory_free(app, part, part->part.max);
|
||||
}
|
||||
arena->part = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
arena_change_chunk_size(Arena *arena, i32_4tech chunk_size){
|
||||
arena->chunk_size = chunk_size;
|
||||
}
|
||||
|
||||
static Partition_Chained*
|
||||
arena__new_part(Arena *arena, i32_4tech new_chunk_size){
|
||||
Application_Links *app = arena->app;
|
||||
i32_4tech memory_size = new_chunk_size + sizeof(Partition_Chained);
|
||||
i32_4tech boundardy = 4096;
|
||||
if (memory_size < boundardy){
|
||||
memory_size = boundardy;
|
||||
}
|
||||
else{
|
||||
memory_size = memory_size + boundardy - 1;
|
||||
memory_size = memory_size - memory_size%boundardy;
|
||||
}
|
||||
void *memory = memory_allocate(app, memory_size);
|
||||
Partition_Chained *part = (Partition_Chained*)memory;
|
||||
part->part = make_part(memory, memory_size);
|
||||
part_allocate(&part->part, sizeof(*part));
|
||||
part->prev = arena->part;
|
||||
arena->part = part;
|
||||
return(part);
|
||||
}
|
||||
|
||||
static Partition_Chained*
|
||||
arena__new_part(Arena *arena){
|
||||
return(arena__new_part(arena, arena->chunk_size));
|
||||
}
|
||||
|
||||
static void
|
||||
arena__align_inner(Arena *arena, i32_4tech b){
|
||||
if (arena->align != 1){
|
||||
Partition_Chained *part = arena->part;
|
||||
if (part == 0){
|
||||
part = arena__new_part(arena);
|
||||
}
|
||||
part_align(&part->part, b);
|
||||
}
|
||||
}
|
||||
|
||||
static void*
|
||||
arena_allocate(Arena *arena, i32_4tech size){
|
||||
void *result = 0;
|
||||
Partition_Chained *part = arena->part;
|
||||
if (part == 0){
|
||||
part = arena__new_part(arena);
|
||||
}
|
||||
arena__align_inner(arena, arena->align);
|
||||
result = part_allocate(&part->part, size);
|
||||
if (result == 0){
|
||||
i32_4tech new_chunk_size = arena->chunk_size;
|
||||
if (size > new_chunk_size){
|
||||
new_chunk_size = size;
|
||||
}
|
||||
part = arena__new_part(arena, new_chunk_size);
|
||||
arena__align_inner(arena, arena->align);
|
||||
result = part_allocate(&part->part, size);
|
||||
}
|
||||
arena->align = 1;
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
arena_align(Arena *arena, i32_4tech b){
|
||||
arena__align_inner(arena, b);
|
||||
arena->align = b;
|
||||
}
|
||||
|
||||
static Partition*
|
||||
arena_use_as_part(Arena *arena, i32_4tech minimum_part_size){
|
||||
if (minimum_part_size < arena->chunk_size){
|
||||
minimum_part_size = arena->chunk_size;
|
||||
}
|
||||
Partition_Chained *part = arena->part;
|
||||
if (part == 0){
|
||||
part = arena__new_part(arena, minimum_part_size);
|
||||
}
|
||||
else{
|
||||
if (part_remaining(&part->part) < minimum_part_size){
|
||||
part = arena__new_part(arena, minimum_part_size);
|
||||
}
|
||||
}
|
||||
return(&part->part);
|
||||
}
|
||||
|
||||
static Temp_Memory_Arena
|
||||
begin_temp_memory(Arena *arena){
|
||||
Temp_Memory_Arena result = {};
|
||||
result.arena = arena;
|
||||
result.part = arena->part;
|
||||
if (result.part != 0){
|
||||
result.pos = result.part->part.pos;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
end_temp_memory(Temp_Memory_Arena temp){
|
||||
Application_Links *app = temp.arena->app;
|
||||
for (Partition_Chained *part = temp.arena->part, *prev = 0;
|
||||
part != temp.part;
|
||||
part = prev){
|
||||
prev = part->prev;
|
||||
memory_free(app, part, part->part.max);
|
||||
}
|
||||
temp.arena->part = temp.part;
|
||||
if (temp.part != 0){
|
||||
temp.part->part.pos = temp.pos;
|
||||
}
|
||||
}
|
||||
|
||||
static void*
|
||||
push_allocator_allocate(Arena *arena, i32_4tech size){
|
||||
return(arena_allocate(arena, size));
|
||||
}
|
||||
|
||||
static void
|
||||
push_allocator_align(Arena *arena, i32_4tech b){
|
||||
arena_align(arena, b);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#define push_array(A, T, size) (T*)push_allocator_allocate((A), sizeof(T)*(size))
|
||||
#define push_align(A, b) push_allocator_align((A), (b))
|
||||
#define reset_temp_memory end_temp_memory
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -51,11 +51,33 @@ struct Partition{
|
|||
};
|
||||
|
||||
struct Temp_Memory{
|
||||
void *handle;
|
||||
Partition *part;
|
||||
i32_4tech pos;
|
||||
};
|
||||
|
||||
#if defined(FCODER_CUSTOM_H)
|
||||
|
||||
struct Partition_Chained{
|
||||
Partition_Chained *prev;
|
||||
Partition part;
|
||||
};
|
||||
|
||||
struct Arena{
|
||||
struct Application_Links *app;
|
||||
Partition_Chained *part;
|
||||
i32_4tech chunk_size;
|
||||
i32_4tech align;
|
||||
};
|
||||
|
||||
struct Temp_Memory_Arena{
|
||||
Arena *arena;
|
||||
Partition_Chained *part;
|
||||
i32_4tech pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ begin_integrated_lister__with_refresh_handler(Application_Links *app, char *quer
|
|||
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
|
||||
Lister_State *state = view_get_lister_state(view);
|
||||
init_lister_state(app, state, heap);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size, 0);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size);
|
||||
lister_set_query_string(&state->lister.data, query_string);
|
||||
state->lister.data.handlers = handlers;
|
||||
handlers.refresh(app, &state->lister);
|
||||
|
@ -336,8 +336,8 @@ begin_integrated_lister__with_refresh_handler(Application_Links *app, char *quer
|
|||
static const int32_t default_string_size_estimation = 0;
|
||||
|
||||
static int32_t
|
||||
lister__get_arena_size(int32_t option_count, int32_t user_data_size,
|
||||
int32_t estimated_string_space_size){
|
||||
lister__get_arena_size_(int32_t option_count, int32_t user_data_size,
|
||||
int32_t estimated_string_space_size){
|
||||
int32_t arena_size = (user_data_size + 7 + option_count*sizeof(Lister_Node) + estimated_string_space_size);
|
||||
return(arena_size);
|
||||
}
|
||||
|
@ -354,9 +354,8 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string,
|
|||
view_begin_ui_mode(app, view);
|
||||
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
|
||||
Lister_State *state = view_get_lister_state(view);
|
||||
int32_t arena_size = lister__get_arena_size(option_count, user_data_size, estimated_string_space_size);
|
||||
init_lister_state(app, state, heap);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size, arena_size);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size);
|
||||
for (int32_t i = 0; i < option_count; i += 1){
|
||||
lister_add_item(&state->lister, options[i].string, options[i].status, options[i].user_data, 0);
|
||||
}
|
||||
|
@ -379,8 +378,7 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_
|
|||
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
|
||||
Lister_State *state = view_get_lister_state(view);
|
||||
init_lister_state(app, state, heap);
|
||||
int32_t arena_size = lister__get_arena_size(option_count, user_data_size, estimated_string_space_size);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size, arena_size);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size);
|
||||
for (int32_t i = 0; i < option_count; i += 1){
|
||||
char *shortcut_chars = options[i].shortcut_chars;
|
||||
int32_t shortcut_chars_length = str_size(shortcut_chars);
|
||||
|
@ -426,8 +424,7 @@ begin_integrated_lister__theme_list(Application_Links *app, char *query_string,
|
|||
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
|
||||
Lister_State *state = view_get_lister_state(view);
|
||||
init_lister_state(app, state, heap);
|
||||
int32_t arena_size = lister__get_arena_size(option_count, user_data_size, estimated_string_space_size);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size, arena_size);
|
||||
lister_first_init(app, &state->lister, user_data, user_data_size);
|
||||
state->lister.data.theme_list = true;
|
||||
for (int32_t i = 0; i < option_count; i += 1){
|
||||
lister_add_theme_item(&state->lister,
|
||||
|
@ -537,11 +534,7 @@ generate_all_buffers_list(Application_Links *app, Lister *lister){
|
|||
|
||||
static void
|
||||
generate_hot_directory_file_list(Application_Links *app, Lister *lister){
|
||||
if (lister->arena.max < (64 << 10)){
|
||||
lister_arena_clear_data_ensure_bytes(app, lister, (64 << 10));
|
||||
}
|
||||
|
||||
Temp_Memory temp = begin_temp_memory(&lister->arena);
|
||||
Temp_Memory_Arena temp = begin_temp_memory(&lister->arena);
|
||||
String hot = get_hot_directory(app, &lister->arena);
|
||||
if (hot.size > 0 && hot.str[hot.size - 1] != '/' && hot.str[hot.size - 1] != '\\'){
|
||||
if (push_array(&lister->arena, char, 1) != 0){
|
||||
|
@ -578,9 +571,8 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
|
|||
info < one_past_last;
|
||||
info += 1){
|
||||
if (!info->folder) continue;
|
||||
String file_name = build_string(&lister->arena,
|
||||
make_string(info->filename, info->filename_len),
|
||||
"/", "");
|
||||
String file_name = build_string(arena_use_as_part(&lister->arena, info->filename_len + 1),
|
||||
make_string(info->filename, info->filename_len), "/", "");
|
||||
lister_add_item(lister, lister_prealloced(file_name), empty_string_prealloced, file_name.str, 0);
|
||||
}
|
||||
|
||||
|
@ -592,21 +584,24 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
|
|||
char *is_loaded = "";
|
||||
char *status_flag = "";
|
||||
|
||||
Temp_Memory path_temp = begin_temp_memory(&lister->arena);
|
||||
String full_file_path = {};
|
||||
full_file_path.size = 0;
|
||||
full_file_path.memory_size = hot.size + 1 + info->filename_len + 1;
|
||||
full_file_path.str = push_array(&lister->arena, char, full_file_path.memory_size);
|
||||
append(&full_file_path, hot);
|
||||
if (full_file_path.size == 0 ||
|
||||
char_is_slash(full_file_path.str[full_file_path.size - 1])){
|
||||
append(&full_file_path, "/");
|
||||
|
||||
Buffer_Summary buffer = {};
|
||||
|
||||
{
|
||||
Temp_Memory_Arena path_temp = begin_temp_memory(&lister->arena);
|
||||
String full_file_path = {};
|
||||
full_file_path.size = 0;
|
||||
full_file_path.memory_size = hot.size + 1 + info->filename_len + 1;
|
||||
full_file_path.str = push_array(&lister->arena, char, full_file_path.memory_size);
|
||||
append(&full_file_path, hot);
|
||||
if (full_file_path.size == 0 ||
|
||||
char_is_slash(full_file_path.str[full_file_path.size - 1])){
|
||||
append(&full_file_path, "/");
|
||||
}
|
||||
append(&full_file_path, make_string(info->filename, info->filename_len));
|
||||
buffer = get_buffer_by_file_name(app, full_file_path.str, full_file_path.size, AccessAll);
|
||||
end_temp_memory(path_temp);
|
||||
}
|
||||
append(&full_file_path, make_string(info->filename, info->filename_len));
|
||||
Buffer_Summary buffer = get_buffer_by_file_name(app,
|
||||
full_file_path.str, full_file_path.size,
|
||||
AccessAll);
|
||||
end_temp_memory(path_temp);
|
||||
|
||||
if (buffer.exists){
|
||||
is_loaded = "LOADED";
|
||||
|
@ -615,7 +610,8 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
|
|||
case DirtyState_UnloadedChanges: status_flag = " !"; break;
|
||||
}
|
||||
}
|
||||
String status = build_string(&lister->arena, is_loaded, status_flag, "");
|
||||
int32_t more_than_enough_memory = 32;
|
||||
String status = build_string(arena_use_as_part(&lister->arena, more_than_enough_memory), is_loaded, status_flag, "");
|
||||
lister_add_item(lister, lister_prealloced(file_name), lister_prealloced(status), file_name.str, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part,
|
|||
CString_Array extension_array){
|
||||
Temp_Memory temp = begin_temp_memory(scratch_part);
|
||||
|
||||
int32_t buffers_to_close_max = partition_remaining(scratch_part)/sizeof(int32_t);
|
||||
int32_t buffers_to_close_max = part_remaining(scratch_part)/sizeof(int32_t);
|
||||
int32_t *buffers_to_close = push_array(scratch_part, int32_t, buffers_to_close_max);
|
||||
|
||||
int32_t buffers_to_close_count = 0;
|
||||
|
@ -922,7 +922,7 @@ set_current_project(Application_Links *app, Partition *scratch, Project *project
|
|||
}
|
||||
else{
|
||||
Temp_Memory temp2 = begin_temp_memory(scratch);
|
||||
String space = string_push(scratch, partition_remaining(scratch));
|
||||
String space = string_push(scratch, part_remaining(scratch));
|
||||
|
||||
{
|
||||
config_feedback_string(&space, "'root_directory'", project->dir);
|
||||
|
@ -1226,7 +1226,7 @@ project_generate_bat_script(Partition *scratch, String opts, String compiler,
|
|||
replace_char(&od, '/', '\\');
|
||||
replace_char(&bf, '/', '\\');
|
||||
|
||||
int32_t space_cap = partition_remaining(scratch);
|
||||
int32_t space_cap = part_remaining(scratch);
|
||||
char *space = push_array(scratch, char, space_cap);
|
||||
String file_name = make_string_cap(space, 0, space_cap);
|
||||
append(&file_name, script_path);
|
||||
|
@ -1267,7 +1267,7 @@ project_generate_sh_script(Partition *scratch, String opts, String compiler,
|
|||
String od = output_dir;
|
||||
String bf = binary_file;
|
||||
|
||||
int32_t space_cap = partition_remaining(scratch);
|
||||
int32_t space_cap = part_remaining(scratch);
|
||||
char *space = push_array(scratch, char, space_cap);
|
||||
String file_name = make_string_cap(space, 0, space_cap);
|
||||
append(&file_name, script_path);
|
||||
|
@ -1318,7 +1318,7 @@ project_generate_project_4coder_file(Partition *scratch,
|
|||
replace_str(&od_win, "/", "\\\\");
|
||||
replace_str(&bf_win, "/", "\\\\");
|
||||
|
||||
int32_t space_cap = partition_remaining(scratch);
|
||||
int32_t space_cap = part_remaining(scratch);
|
||||
char *space = push_array(scratch, char, space_cap);
|
||||
String file_name = make_string_cap(space, 0, space_cap);
|
||||
append(&file_name, script_path);
|
||||
|
|
|
@ -639,7 +639,7 @@ list__parameters(Application_Links *app, Heap *heap, Partition *scratch,
|
|||
|
||||
// List all locations into search buffer
|
||||
Temp_Memory all_temp = begin_temp_memory(scratch);
|
||||
Partition line_part = partition_sub_part(scratch, (4 << 10));
|
||||
Partition line_part = part_sub_part(scratch, (4 << 10));
|
||||
Temp_Memory temp = begin_temp_memory(scratch);
|
||||
Buffer_ID prev_match_id = 0;
|
||||
bool32 no_matches = true;
|
||||
|
|
|
@ -208,29 +208,6 @@ lister_standard_arena_size_round_up(int32_t arena_size){
|
|||
return(arena_size);
|
||||
}
|
||||
|
||||
static void
|
||||
lister_arena_clear_data_ensure_bytes(Application_Links *app, Lister *lister, int32_t minimum_bytes){
|
||||
if (lister->arena.base == 0 || lister->arena.max < minimum_bytes){
|
||||
int32_t rounded_user_data_size = lister->data.user_data_size;
|
||||
rounded_user_data_size += 7;
|
||||
rounded_user_data_size -= rounded_user_data_size%8;
|
||||
int32_t new_size = (lister->arena.max + rounded_user_data_size + minimum_bytes + 1)*2;
|
||||
new_size = lister_standard_arena_size_round_up(new_size);
|
||||
void *new_memory = memory_allocate(app, new_size);
|
||||
memcpy(new_memory, lister->data.user_data, lister->data.user_data_size);
|
||||
lister->data.user_data = new_memory;
|
||||
if (lister->arena.base != 0){
|
||||
memory_free(app, lister->arena.base, lister->arena.max);
|
||||
}
|
||||
lister->arena = make_part(new_memory, new_size);
|
||||
push_array(&lister->arena, char, lister->data.user_data_size);
|
||||
}
|
||||
else{
|
||||
lister->arena.pos = lister->data.user_data_size;
|
||||
}
|
||||
push_align(&lister->arena, 8);
|
||||
}
|
||||
|
||||
static void
|
||||
init_lister_state(Application_Links *app, Lister_State *state, Heap *heap){
|
||||
state->initialized = true;
|
||||
|
@ -238,9 +215,7 @@ init_lister_state(Application_Links *app, Lister_State *state, Heap *heap){
|
|||
state->item_index = 0;
|
||||
state->set_view_vertical_focus_to_item = false;
|
||||
state->item_count_after_filter = 0;
|
||||
if (state->lister.arena.base != 0){
|
||||
memory_free(app, state->lister.arena.base, state->lister.arena.max);
|
||||
}
|
||||
arena_release_all(&state->lister.arena);
|
||||
memset(&state->lister, 0, sizeof(state->lister));
|
||||
}
|
||||
|
||||
|
@ -456,29 +431,23 @@ lister_prealloced(String string){
|
|||
}
|
||||
|
||||
static void
|
||||
lister_first_init(Application_Links *app, Lister *lister, void *user_data, int32_t user_data_size, int32_t arena_size){
|
||||
lister_first_init(Application_Links *app, Lister *lister, void *user_data, int32_t user_data_size){
|
||||
memset(lister, 0, sizeof(*lister));
|
||||
lister->arena = make_arena(app, (16 << 10));
|
||||
lister->data.query = make_fixed_width_string(lister->data.query_space);
|
||||
lister->data.text_field = make_fixed_width_string(lister->data.text_field_space);
|
||||
lister->data.key_string = make_fixed_width_string(lister->data.key_string_space);
|
||||
if (arena_size < user_data_size){
|
||||
arena_size = user_data_size;
|
||||
}
|
||||
lister->data.user_data_size = 0;
|
||||
if (arena_size != 0){
|
||||
lister_arena_clear_data_ensure_bytes(app, lister, arena_size);
|
||||
lister->data.user_data = push_array(&lister->arena, char, user_data_size);
|
||||
push_align(&lister->arena, 8);
|
||||
if (user_data != 0){
|
||||
memcpy(lister->data.user_data, user_data, user_data_size);
|
||||
}
|
||||
lister->data.user_data_size = user_data_size;
|
||||
lister->data.user_data = push_array(&lister->arena, char, user_data_size);
|
||||
lister->data.user_data_size = user_data_size;
|
||||
push_align(&lister->arena, 8);
|
||||
if (user_data != 0){
|
||||
memcpy(lister->data.user_data, user_data, user_data_size);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
lister_begin_new_item_set(Application_Links *app, Lister *lister, int32_t list_memory_size){
|
||||
lister_arena_clear_data_ensure_bytes(app, lister, list_memory_size);
|
||||
arena_release_all(&lister->arena);
|
||||
memset(&lister->data.options, 0, sizeof(lister->data.options));
|
||||
}
|
||||
|
||||
|
@ -574,10 +543,7 @@ lister_default(Application_Links *app, Partition *scratch, Heap *heap,
|
|||
{
|
||||
view_end_ui_mode(app, view);
|
||||
state->initialized = false;
|
||||
if (state->lister.arena.base != 0){
|
||||
memory_free(app, state->lister.arena.base, state->lister.arena.max);
|
||||
memset(&state->lister.arena, 0, sizeof(state->lister.arena));
|
||||
}
|
||||
arena_release_all(&state->lister.arena);
|
||||
}break;
|
||||
|
||||
case ListerActivation_Continue:
|
||||
|
|
|
@ -70,7 +70,7 @@ struct Lister_Data{
|
|||
};
|
||||
|
||||
struct Lister{
|
||||
Partition arena;
|
||||
Arena arena;
|
||||
Lister_Data data;
|
||||
};
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
internal CLI_List
|
||||
make_cli_list(Partition *part, u32 max){
|
||||
CLI_List list = {};
|
||||
partition_align(part, 8);
|
||||
push_align(part, 8);
|
||||
list.procs = push_array(part, CLI_Process, max);
|
||||
list.max = max;
|
||||
return(list);
|
||||
|
|
|
@ -483,7 +483,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
|
|||
|
||||
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width));
|
||||
|
||||
max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair);
|
||||
max_wrap_indent_mark = part_remaining(part)/sizeof(Wrap_Indent_Pair);
|
||||
wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark);
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
|
|||
edit_fix_markers(system, models, file, layout, desc);
|
||||
|
||||
// NOTE(allen): actual text replacement
|
||||
i32 scratch_size = partition_remaining(part);
|
||||
i32 scratch_size = part_remaining(part);
|
||||
Assert(scratch_size > 0);
|
||||
i32 request_amount = 0;
|
||||
Assert(end <= buffer_size(&file->state.buffer));
|
||||
|
@ -341,7 +341,7 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file, Edit_Sp
|
|||
edit_fix_markers(system, models, file, layout, desc);
|
||||
|
||||
// NOTE(allen): actual text replacement
|
||||
i32 scratch_size = partition_remaining(part);
|
||||
i32 scratch_size = part_remaining(part);
|
||||
Buffer_Batch_State state = {};
|
||||
i32 request_amount = 0;
|
||||
for (;buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount);){
|
||||
|
|
|
@ -412,7 +412,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
|
|||
buffer_init_provide_page(&init, data, page_size);
|
||||
}
|
||||
|
||||
i32 scratch_size = partition_remaining(part);
|
||||
i32 scratch_size = part_remaining(part);
|
||||
Assert(scratch_size > 0);
|
||||
b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size);
|
||||
AllowLocal(init_success); Assert(init_success);
|
||||
|
|
|
@ -190,14 +190,14 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
|
|||
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, partition_current(part), partition_remaining(part));
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
|
||||
Assert(parse_context.valid);
|
||||
push_array(part, char, (i32)parse_context.memory_size);
|
||||
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 text_size = buffer_size(buffer);
|
||||
|
||||
i32 mem_size = partition_remaining(part);
|
||||
i32 mem_size = part_remaining(part);
|
||||
|
||||
Cpp_Token_Array new_tokens;
|
||||
new_tokens.max_count = mem_size/sizeof(Cpp_Token);
|
||||
|
@ -305,7 +305,7 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
|
|||
relex_range.end_token_index - relex_range.start_token_index + extra_tolerance;
|
||||
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, partition_current(part), partition_remaining(part));
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
|
||||
Assert(parse_context.valid);
|
||||
push_array(part, char, (i32)parse_context.memory_size);
|
||||
|
||||
|
@ -429,13 +429,13 @@ file_relex_serial(System_Functions *system, Models *models, Editing_File *file,
|
|||
Cpp_Token_Array *array = &file->state.token_array;
|
||||
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, partition_current(part), partition_remaining(part));
|
||||
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
|
||||
Assert(parse_context.valid);
|
||||
push_array(part, char, (i32)parse_context.memory_size);
|
||||
|
||||
Cpp_Token_Array relex_array;
|
||||
relex_array.count = 0;
|
||||
relex_array.max_count = partition_remaining(part) / sizeof(Cpp_Token);
|
||||
relex_array.max_count = part_remaining(part) / sizeof(Cpp_Token);
|
||||
relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count);
|
||||
|
||||
i32 size = buffer_size(buffer);
|
||||
|
|
|
@ -737,8 +737,8 @@ system_font_get_local_stubs(Partition *part){
|
|||
terminate_with_null(&dir_str);
|
||||
dir_len = dir_str.size;
|
||||
|
||||
partition_reduce(part, dir_max - dir_len - 1);
|
||||
partition_align(part, 8);
|
||||
part_reduce(part, dir_max - dir_len - 1);
|
||||
push_align(part, 8);
|
||||
|
||||
File_List file_list = {};
|
||||
system_set_file_list(&file_list, (char*)directory, 0, 0, 0);
|
||||
|
@ -753,7 +753,7 @@ system_font_get_local_stubs(Partition *part){
|
|||
if (dir_len + len + 1 <= sizeof(list.first->stub.name)){
|
||||
Font_Setup *setup = push_array(part, Font_Setup, 1);
|
||||
memset(setup, 0, sizeof(*setup));
|
||||
partition_align(part, 8);
|
||||
part_align(part, 8);
|
||||
|
||||
sll_push(list.first, list.last, setup);
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ Render_Begin_Push_Sig(render_internal_begin_push, t, ptr, size){
|
|||
internal
|
||||
Render_End_Push_Sig(render_internal_end_push, t, h){
|
||||
if (h != 0){
|
||||
u8 *end_ptr = (u8*)push_align(&t->buffer, 8);
|
||||
push_align(&t->buffer, 8);
|
||||
u8 *end_ptr = push_array(&t->buffer, u8, 0);
|
||||
Render_Command_Header *header = (Render_Command_Header*)h;
|
||||
header->size = (i32)(end_ptr - (u8*)h);
|
||||
}
|
||||
|
|
|
@ -1197,11 +1197,11 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
|
|||
Partition *part = &models->mem.part;
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
|
||||
partition_align(part, 4);
|
||||
push_align(part, 4);
|
||||
|
||||
f32 left_side_space = 0;
|
||||
|
||||
i32 max = partition_remaining(part)/sizeof(Buffer_Render_Item);
|
||||
i32 max = part_remaining(part)/sizeof(Buffer_Render_Item);
|
||||
Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, 0);
|
||||
|
||||
b32 wrapped = !file->settings.unwrapped_lines;
|
||||
|
|
Loading…
Reference in New Issue