aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odinfmt.bat2
-rw-r--r--src/odin/printer/document.odin25
-rw-r--r--src/odin/printer/printer.odin2
-rw-r--r--tools/odinfmt/main.odin13
4 files changed, 22 insertions, 20 deletions
diff --git a/odinfmt.bat b/odinfmt.bat
index 8b9c022..c31e434 100644
--- a/odinfmt.bat
+++ b/odinfmt.bat
@@ -1 +1 @@
-odin build tools/odinfmt/main.odin -file -show-timings -collection:shared=src -out:odinfmt.exe -o:minimal
+odin build tools/odinfmt/main.odin -file -show-timings -collection:shared=src -out:odinfmt.exe -o:speed
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin
index 8a3f858..c2e59ea 100644
--- a/src/odin/printer/document.odin
+++ b/src/odin/printer/document.odin
@@ -215,17 +215,12 @@ group :: proc(grouped_document: ^Document, options := Document_Group_Options{},
cons :: proc(elems: ..^Document, allocator := context.allocator) -> ^Document {
document := new(Document, allocator)
- elements := make([dynamic]^Document, allocator)
+ elements := make([dynamic]^Document, 0, len(elems), allocator)
+
for elem in elems {
- #partial switch e in elem {
- case Document_Nil:
- continue
- case Document_Cons:
- append(&elements, ..e.elements)
- case:
- append(&elements, elem)
- }
+ append(&elements, elem)
}
+
c := Document_Cons {
elements = elements[:],
}
@@ -264,6 +259,8 @@ Tuple :: struct {
document: ^Document,
}
+list_fits: [dynamic]Tuple
+
fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
assert(list != nil)
@@ -357,6 +354,8 @@ format :: proc(width: int, list: ^[dynamic]Tuple, builder: ^strings.Builder, p:
suffix_builder := strings.builder_make()
+ list_fits = make([dynamic]Tuple, 0, 100, p.allocator)
+
for len(list) != 0 {
data: Tuple = pop(list)
@@ -425,20 +424,20 @@ format :: proc(width: int, list: ^[dynamic]Tuple, builder: ^strings.Builder, p:
break
}
- l := make([dynamic]Tuple, 0, len(list))
+ clear(&list_fits)
for element in list {
- append(&l, element)
+ append(&list_fits, element)
}
- append(&l, Tuple {indentation = data.indentation, mode = .Fit, document = v.document, alignment = data.alignment})
+ append(&list_fits, Tuple {indentation = data.indentation, mode = .Fit, document = v.document, alignment = data.alignment})
recalculate = false
if data.mode == .Fit {
append(list, Tuple {indentation = data.indentation, mode = .Fit, document = v.document, alignment = data.alignment})
}
- else if fits(width-consumed, &l) && v.mode != .Break {
+ else if fits(width-consumed, &list_fits) && v.mode != .Break {
append(list, Tuple {indentation = data.indentation, mode = .Flat, document = v.document, alignment = data.alignment})
} else {
if v.mode == .Fit {
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin
index 183ed75..c37e0fa 100644
--- a/src/odin/printer/printer.odin
+++ b/src/odin/printer/printer.odin
@@ -174,7 +174,7 @@ print_expr :: proc(p: ^Printer, expr: ^ast.Expr) -> string {
print_file :: proc(p: ^Printer, file: ^ast.File) -> string {
p.comments = file.comments
- p.string_builder = strings.builder_make(p.allocator)
+ p.string_builder = strings.builder_make(0, len(file.src)*2, p.allocator)
p.src = file.src
context.allocator = p.allocator
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin
index 6fca27f..77f1379 100644
--- a/tools/odinfmt/main.odin
+++ b/tools/odinfmt/main.odin
@@ -64,9 +64,8 @@ walk_files :: proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip
}
main :: proc() {
-
arena: mem.Arena;
- mem.init_arena(&arena, make([]byte, 20 * mem.Megabyte));
+ mem.init_arena(&arena, make([]byte, 50 * mem.Megabyte));
arena_allocator := mem.arena_allocator(&arena);
@@ -88,6 +87,8 @@ main :: proc() {
write_failure := false;
+ watermark := 0
+
if os.is_file(path) {
if _, ok := args.write.(bool); ok {
backup_path := strings.concatenate({path, "_bk"});
@@ -118,7 +119,6 @@ main :: proc() {
defer delete(backup_path);
if data, ok := format_file(file, arena_allocator); ok {
-
if _, ok := args.write.(bool); ok {
os.rename(file, backup_path);
@@ -133,10 +133,13 @@ main :: proc() {
write_failure = true;
}
+ watermark = max(watermark, arena.offset)
+
free_all(arena_allocator);
}
-
- fmt.printf("formatted %v files in %vms", len(files), time.duration_milliseconds(time.tick_lap_time(&tick_time)));
+
+ fmt.printf("formatted %v files in %vms \n", len(files), time.duration_milliseconds(time.tick_lap_time(&tick_time)));
+ fmt.printf("peak used memory: %v \n", watermark / mem.Megabyte)
} else {
fmt.eprintf("%v is neither a directory nor a file \n", path);
os.exit(1);