Allocate Scope_Delims and Notes from free list before allocating in chunks

This commit is contained in:
Peter Slattery 2025-07-30 17:03:34 -07:00
parent 69dc4f8e04
commit 6d7f1281b2
2 changed files with 64 additions and 17 deletions

View File

@ -29,10 +29,6 @@ struct Code_Index_Scope_Delim {
struct Code_Index_Scope_Delim_List {
Code_Index_Scope_Delim* first;
Code_Index_Scope_Delim* last;
};
struct Code_Index_Scope_Delim_Ptr_Array {
Code_Index_Scope_Delim** ptrs;
i32 count;
};
@ -95,10 +91,11 @@ struct Code_Index_Note_List{
struct Code_Index_File{
Code_Index_Scope_Delim_List scope_delim_list;
Code_Index_Scope_Delim_Ptr_Array scope_delim_array;
Code_Index_Nest_List nest_list;
Code_Index_Note_List note_list;
Buffer_ID buffer;
Code_Index_Scope_Delim* scope_delim_free;
Code_Index_Note* note_free;
};
struct Code_Index_File_Storage{

View File

@ -356,10 +356,44 @@ tree_sitter_node_to_range(TSNode node)
return result;
}
function Code_Index_Scope_Delim*
code_index_new_scope_delim(Code_Index_File* index, Arena* arena, Code_Index_Scope_Delim_Kind kind, Range_i64 range)
{
if (!index->scope_delim_free)
{
int count = 32;
Code_Index_Scope_Delim* arr = push_array_zero(arena, Code_Index_Scope_Delim, count);
for (int i = 0; i < count-1; i++) arr[i].next = &arr[i+1];
index->scope_delim_free = arr;
}
Code_Index_Scope_Delim *result = index->scope_delim_free;
index->scope_delim_free = result->next;
result->next = 0;
sll_queue_push(index->scope_delim_list.first, index->scope_delim_list.last, result);
index->scope_delim_list.count += 1;
result->kind = kind;
result->pos = range;
return result;
}
function Code_Index_Note*
code_index_new_note(Code_Index_File* index, Arena* arena, Code_Index_Note_Kind kind, Range_i64 range, Code_Index_Nest_Stack* parent)
{
Code_Index_Note *result = push_array(arena, Code_Index_Note, 1);
if (!index->note_free)
{
int count = 32;
Code_Index_Note* arr = push_array_zero(arena, Code_Index_Note, count);
for (int i = 0; i < count-1; i++) arr[i].next = &arr[i+1];
index->note_free = arr;
}
Code_Index_Note *result = index->note_free;
index->note_free = result->next;
result->next = 0;
sll_queue_push(index->note_list.first, index->note_list.last, result);
index->note_list.count += 1;
result->file = index;
@ -373,6 +407,7 @@ function Tree_Sitter_Code_Index_Update_State
tree_sitter_code_index_update_state_create(
Application_Links* app,
Buffer_ID buffer_id,
Code_Index_File_Storage code_index_storage,
Arena* scratch
){
Tree_Sitter_Code_Index_Update_State state = {};
@ -380,8 +415,8 @@ tree_sitter_code_index_update_state_create(
state.buffer_id = buffer_id;
state.language = tree_sitter_language_for_buffer(app, state.buffer_id);
if (!state.language) return state;
state.index_arena = make_arena_system(KB(16));
state.index = push_array_zero(&state.index_arena, Code_Index_File, 1);
state.index_arena = code_index_storage.arena;
state.index = code_index_storage.file;
state.buffer_contents = push_whole_buffer(app, scratch, state.buffer_id);
state.query = tree_sitter_query_init(
app, state.buffer_id, state.language->queries.ptr[Tree_Sitter_Language_Query_Tags]
@ -391,6 +426,21 @@ tree_sitter_code_index_update_state_create(
state.last_note = 0;
state.last_note_match_id = max_u32;
state.ok = true;
if (state.index->scope_delim_list.last) {
state.index->scope_delim_list.last->next = state.index->scope_delim_free;
}
state.index->scope_delim_free = state.index->scope_delim_list.first;
state.index->scope_delim_list.first = 0;
state.index->scope_delim_list.last = 0;
if (state.index->note_list.last) {
state.index->note_list.last->next = state.index->note_free;
}
state.index->note_free = state.index->note_list.first;
state.index->note_list.first = 0;
state.index->note_list.last = 0;
return state;
}
@ -425,15 +475,7 @@ tree_sitter_code_index_update_process_query_match(
if (!skip)
{
Code_Index_Scope_Delim* delim = push_array_zero(&state->index_arena, Code_Index_Scope_Delim, 1);
delim->pos = type_range;
delim->kind = kind;
Code_Index_Scope_Delim_List* list = &state->index->scope_delim_list;
if (!list->first) list->first = delim;
if (list->last) list->last->next = delim;
delim->prev = list->last;
list->last = delim;
code_index_new_scope_delim(state->index, &state->index_arena, kind, type_range);
}
}
else if (string_match(capture_name, SCu8("definition.class")))
@ -569,9 +611,13 @@ tree_sitter_code_index_update_full_file(Application_Links* app, Buffer_ID buffer
{
Scratch_Block scratch(app);
Code_Index_File_Storage storage;
storage.arena = make_arena_system(KB(16));
storage.file = push_array_zero(&storage.arena, Code_Index_File, 1);
Tree_Sitter_Code_Index_Update_State state = tree_sitter_code_index_update_state_create(
app,
buffer_id,
storage,
scratch
);
@ -600,9 +646,13 @@ tree_sitter_code_index_update_async(Async_Context* actx, String_Const_u8 data)
Scratch_Block scratch(app);
acquire_global_frame_mutex(app);
Code_Index_File_Storage storage;
storage.arena = make_arena_system(KB(16));
storage.file = push_array_zero(&storage.arena, Code_Index_File, 1);
Tree_Sitter_Code_Index_Update_State state = tree_sitter_code_index_update_state_create(
app,
buffer_id,
storage,
scratch
);
release_global_frame_mutex(app);