aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai42
1 files changed, 11 insertions, 31 deletions
diff --git a/ttt.jai b/ttt.jai
index 7701670..aa511ea 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -349,32 +349,14 @@ delete_task :: (using db: *Database, index: s64) -> bool { // TODO Maybe use `us
active_idx = -1;
}
- // TODO Helper function.
- get_msb :: (value: s64) -> msb: s64, found: bool {
- result: s64 = ---;
- #asm {
- bsr result, value;
+ // Try to shrink database capacity if using more than 2MB.
+ if (tasks.allocated >> 2) > tasks.count && tasks.allocated * SIZE_OF_TASK > 2_000_000 {
+ new_capacity := tasks.allocated >> 1;
+ new_tasks_data := realloc(tasks.data, new_capacity * SIZE_OF_TASK, tasks.allocated * SIZE_OF_TASK, tasks.allocator);
+ if new_tasks_data != null {
+ tasks.data = new_tasks_data;
+ tasks.allocated = new_capacity;
}
- return result * xx cast(bool)value, xx value; // If value is zero: return `0, false`.
- }
-
- my_array_reserve_nonpoly :: (array: *[..] *void, desired_items: s64, size: s64) -> success: bool {
- if !array.allocator.proc remember_allocators(array);
-
- new_array_data := realloc(array.data, desired_items * size, array.allocated * size, array.allocator);
- if new_array_data == null return false;
-
- array.data = new_array_data;
- array.allocated = desired_items;
- return true;
- }
-
- // If possible, shrink database capacity.
- // TODO Do we really want to make this fuss?
- current_capacity := tasks.allocated;
- if (tasks.count < (current_capacity >> 2)) {
- new_capacity := 1 << (get_msb(tasks.count) + 2);
- my_array_reserve_nonpoly(xx *tasks, new_capacity, SIZE_OF_TASK);
}
return true;
@@ -462,7 +444,6 @@ update_total_times :: (db: *Database) {
totals: []s64 = db.total_times;
memset(totals.data, 0, NUM_WEEK_DAYS * size_of(s64));
for db.tasks {
- // TODO Try to use local variables instead of total sub...something... the indexes thingy.
times : []s64 = it.times;
totals[0] = add(totals[0], times[0]);
totals[1] = add(totals[1], times[1]);
@@ -592,8 +573,6 @@ load_database :: (db: *Database, path: string) -> success: bool {
// Returns success.
export_to_csv :: (db: Database, path: string) -> success: bool {
assert(xx path, ASSERT_NOT_EMPTY, "path");
- // TODO Make sure (IN ALL PROCEDURES) we're not receiving an empty path.
-
builder: String_Builder;
defer reset(*builder);
@@ -608,8 +587,7 @@ export_to_csv :: (db: Database, path: string) -> success: bool {
memcpy(name.data, it.name.data, name.count);
replace_chars(name, ",", #char " ");
print_to_builder(*builder, "%,%,%,%,%,%,%,%\n",
- name, it.times[0], it.times[1], it.times[2],
- it.times[3], it.times[4], it.times[5], it.times[6]);
+ name, it.times[0], it.times[1], it.times[2], it.times[3], it.times[4], it.times[5], it.times[6]);
}
write_entire_file(path, *builder);
@@ -762,7 +740,8 @@ append_to_csv :: (task: Task, path: string) -> success: bool {
task_name := copy_temporary_string(xx task.name); // TODO Cleanup this temp mess.
replace_chars(task_name, ",", #char " ");
- csv_line := tprint("%,%,%,%,%,%,%,%\n", task_name, task.times[0], task.times[1], task.times[2], task.times[3], task.times[4], task.times[5], task.times[6]);
+ csv_line := tprint("%,%,%,%,%,%,%,%\n",
+ task_name, task.times[0], task.times[1], task.times[2], task.times[3], task.times[4], task.times[5], task.times[6]);
file_write(*file, csv_line);
return true;
@@ -1782,3 +1761,4 @@ main :: () {
exit(xx ifx error_saving then 1 else 0);
}
+