diff options
| author | Tobias Mollstam <tobias@mollstam.com> | 2026-01-12 20:33:44 +0100 |
|---|---|---|
| committer | Tobias Mollstam <tobias@mollstam.com> | 2026-01-12 20:41:55 +0100 |
| commit | c47a8d5d40a1d1c94eb71f7abcd2b1b48138dd2a (patch) | |
| tree | ff73eb1167228a25f5178d76e4792c7becf56194 | |
| parent | 03d564b758d8c3942bcea7dc1eff6ad8211b71ea (diff) | |
use default heap allocator instead of fixed size arena for odinfmt CLI
| -rw-r--r-- | tools/odinfmt/main.odin | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin index 3470ca5..68d002c 100644 --- a/tools/odinfmt/main.odin +++ b/tools/odinfmt/main.odin @@ -44,11 +44,6 @@ walk_files :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> ( } main :: proc() { - arena: mem.Arena - mem.arena_init(&arena, make([]byte, 50 * mem.Megabyte)) - - arena_allocator := mem.arena_allocator(&arena) - init_global_temporary_allocator(mem.Megabyte * 20) //enough space for the walk args: Args @@ -70,12 +65,10 @@ main :: proc() { write_failure := false - watermark := 0 - config := format.find_config_file_or_default(args.path) if args.stdin { - data := make([dynamic]byte, arena_allocator) + data := make([dynamic]byte) for { tmp: [mem.Kilobyte]byte @@ -86,7 +79,7 @@ main :: proc() { append(&data, ..tmp[:r]) } - source, ok := format.format("<stdin>", string(data[:]), config, {.Optional_Semicolons}, arena_allocator) + source, ok := format.format("<stdin>", string(data[:]), config, {.Optional_Semicolons}) if ok { fmt.println(source) @@ -98,7 +91,7 @@ main :: proc() { backup_path := strings.concatenate({args.path, "_bk"}) defer delete(backup_path) - if data, ok := format_file(args.path, config, arena_allocator); ok { + if data, ok := format_file(args.path, config); ok { os.rename(args.path, backup_path) if os.write_entire_file(args.path, transmute([]byte)data) { @@ -109,7 +102,7 @@ main :: proc() { write_failure = true } } else { - if data, ok := format_file(args.path, config, arena_allocator); ok { + if data, ok := format_file(args.path, config); ok { fmt.println(data) } } @@ -122,7 +115,7 @@ main :: proc() { backup_path := strings.concatenate({file, "_bk"}) defer delete(backup_path) - if data, ok := format_file(file, config, arena_allocator); ok { + if data, ok := format_file(file, config); ok { if args.write { os.rename(file, backup_path) @@ -136,10 +129,6 @@ main :: proc() { fmt.eprintf("Failed to format %v", file) write_failure = true } - - watermark = max(watermark, arena.offset) - - free_all(arena_allocator) } fmt.printf( @@ -147,7 +136,6 @@ main :: proc() { len(files), time.duration_milliseconds(time.tick_lap_time(&tick_time)), ) - fmt.printf("Peak memory used: %v \n", watermark / mem.Megabyte) } else { fmt.eprintf("%v is neither a directory nor a file \n", args.path) os.exit(1) |