diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-21 00:55:49 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-06-21 00:55:49 +0200 |
| commit | 02658e0ea297f5f906acd2b887def53deac3698e (patch) | |
| tree | d346d61dc6fafb1cbba0a02c130df85900732efb /src/server | |
| parent | 1edbffe4a4f4094374ecb58e8bf686f998dd1451 (diff) | |
Move to new allocator for documents.
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/caches.odin | 3 | ||||
| -rw-r--r-- | src/server/documents.odin | 23 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/server/caches.odin b/src/server/caches.odin index 73a7613..f8ca0d0 100644 --- a/src/server/caches.odin +++ b/src/server/caches.odin @@ -3,6 +3,7 @@ package server import "src:common" import "core:time" +import "core:mem/virtual" //Used in semantic tokens and inlay hints to handle the entire file being resolved. @@ -20,7 +21,7 @@ file_resolve_cache: FileResolveCache resolve_entire_file_cached :: proc(document: ^Document) -> map[uintptr]SymbolAndNode { if document.uri.uri not_in file_resolve_cache.files { file_resolve_cache.files[document.uri.uri] = FileResolve { - symbols = resolve_entire_file(document, .None, common.scratch_allocator(document.allocator)), + symbols = resolve_entire_file(document, .None, virtual.arena_allocator(document.allocator)), } } diff --git a/src/server/documents.odin b/src/server/documents.odin index eca2938..dee90d5 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -5,6 +5,7 @@ import "base:intrinsics" import "core:fmt" import "core:log" import "core:mem" +import "core:mem/virtual" import "core:odin/ast" import "core:odin/parser" import "core:odin/tokenizer" @@ -40,7 +41,7 @@ Document :: struct { ast: ast.File, imports: []Package, package_name: string, - allocator: ^common.Scratch_Allocator, //because parser does not support freeing I use arena allocators for each document + allocator: ^virtual.Arena, //because parser does not support freeing I use arena allocators for each document operating_on: int, //atomic version: Maybe(int), } @@ -48,20 +49,20 @@ Document :: struct { DocumentStorage :: struct { documents: map[string]Document, - free_allocators: [dynamic]^common.Scratch_Allocator, + free_allocators: [dynamic]^virtual.Arena, } document_storage: DocumentStorage document_storage_shutdown :: proc() { for k, v in document_storage.documents { - common.scratch_allocator_destroy(v.allocator) + virtual.arena_destroy(v.allocator) free(v.allocator) delete(k) } for alloc in document_storage.free_allocators { - common.scratch_allocator_destroy(alloc) + virtual.arena_destroy(alloc) free(alloc) } @@ -69,18 +70,18 @@ document_storage_shutdown :: proc() { delete(document_storage.documents) } -document_get_allocator :: proc() -> ^common.Scratch_Allocator { +document_get_allocator :: proc() -> ^virtual.Arena { if len(document_storage.free_allocators) > 0 { return pop(&document_storage.free_allocators) } else { - allocator := new(common.Scratch_Allocator) - common.scratch_allocator_init(allocator, mem.Megabyte * 3) + allocator := new(virtual.Arena) + _ = virtual.arena_init_growing(allocator) return allocator } } -document_free_allocator :: proc(allocator: ^common.Scratch_Allocator) { - free_all(common.scratch_allocator(allocator)) +document_free_allocator :: proc(allocator: ^virtual.Arena) { + free_all(virtual.arena_allocator(allocator)) append(&document_storage.free_allocators, allocator) } @@ -394,9 +395,9 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([]Parser delete_key(&file_resolve_cache.files, document.uri.uri) } - free_all(common.scratch_allocator(document.allocator)) + free_all(virtual.arena_allocator(document.allocator)) - context.allocator = common.scratch_allocator(document.allocator) + context.allocator = virtual.arena_allocator(document.allocator) pkg := new(ast.Package) pkg.kind = .Normal |