mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-21 05:05:00 -07:00
Use templated Array with bounds checking
This commit is contained in:
+5
-5
@@ -6,7 +6,7 @@ typedef struct TimeStamp {
|
||||
|
||||
typedef struct Timings {
|
||||
TimeStamp total;
|
||||
Array(TimeStamp) sections;
|
||||
Array<TimeStamp> sections;
|
||||
u64 freq;
|
||||
} Timings;
|
||||
|
||||
@@ -83,7 +83,7 @@ TimeStamp make_time_stamp(String label) {
|
||||
}
|
||||
|
||||
void timings_init(Timings *t, String label, isize buffer_size) {
|
||||
array_init_reserve(&t->sections, heap_allocator(), buffer_size);
|
||||
array_init(&t->sections, heap_allocator(), buffer_size);
|
||||
t->total = make_time_stamp(label);
|
||||
t->freq = time_stamp__freq();
|
||||
}
|
||||
@@ -94,7 +94,7 @@ void timings_destroy(Timings *t) {
|
||||
|
||||
void timings__stop_current_section(Timings *t) {
|
||||
if (t->sections.count > 0) {
|
||||
t->sections.e[t->sections.count-1].finish = time_stamp_time_now();
|
||||
t->sections[t->sections.count-1].finish = time_stamp_time_now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ void timings_print_all(Timings *t) {
|
||||
|
||||
max_len = t->total.label.len;
|
||||
for_array(i, t->sections) {
|
||||
TimeStamp ts = t->sections.e[i];
|
||||
TimeStamp ts = t->sections[i];
|
||||
max_len = gb_max(max_len, ts.label.len);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ void timings_print_all(Timings *t) {
|
||||
time_stamp_as_ms(t->total, t->freq));
|
||||
|
||||
for_array(i, t->sections) {
|
||||
TimeStamp ts = t->sections.e[i];
|
||||
TimeStamp ts = t->sections[i];
|
||||
gb_printf("%.*s%.*s - %.3f ms\n",
|
||||
LIT(ts.label),
|
||||
cast(int)(max_len-ts.label.len), SPACES,
|
||||
|
||||
Reference in New Issue
Block a user