diff options
| author | dam <dam@gudinoff> | 2024-05-07 10:27:22 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2024-05-07 10:27:22 +0100 |
| commit | 8779553b877a2bb728ddf9d7c21b272c2eedb653 (patch) | |
| tree | 523f64af3907b04cc9488d7bedd00f8c0fb0229d /ttt.jai | |
| parent | 27e3e029448cf2a80b24e6e212dee8cccda06987 (diff) | |
| download | task-time-tracker-8779553b877a2bb728ddf9d7c21b272c2eedb653.tar.zst task-time-tracker-8779553b877a2bb728ddf9d7c21b272c2eedb653.zip | |
Fixed biggest performance bottleneck on draw_user_interface: print white spaces.
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -719,8 +719,8 @@ import_from_csv :: (db: *Database, path: string) -> bool { csv_values := split(line, ",",, temporary_allocator); // Truncate and import task name. - truncate(*csv_values[0], task.name.count); - memcpy(task.name.data, csv_values[0].data, csv_values[0].count); + task_name := truncate(csv_values[0], task.name.count); + memcpy(task.name.data, task_name.data, task_name.count); advance(*csv_values); for csv_values @@ -901,11 +901,11 @@ draw_user_interface :: (db: *Database, layout: *Layout) { start := current_time_monotonic(); // DEBUG - - - - // TODO During dirty_flag revamp...we may also start using the String_Builder. - + auto_release_temp(); + + empty_line := talloc_string(size_x); + memset(empty_line.data, #char " ", size_x); + adjust_first_day_of_week := int.[ (0 + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS, (1 + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS, @@ -1004,6 +1004,7 @@ draw_user_interface :: (db: *Database, layout: *Layout) { idx_start := (db.selected_idx / layout_tasks_rows) * layout_tasks_rows; // Display up to rows allowed by the layout, or less if reached end of database. idx_stop := idx_start + (ifx layout_tasks_rows > db.tasks.count - idx_start then db.tasks.count - idx_start else layout_tasks_rows); + for task_idx: idx_start..idx_stop-1 { task := *db.tasks[task_idx]; y += 1; @@ -1026,19 +1027,18 @@ draw_user_interface :: (db: *Database, layout: *Layout) { // Task title. x += 1; column_width = layout.columns[L_TITLE_IDX].width; - // mvprintw(xx y, xx x, "%-*.*s", column_width, column_width, temp_c_string(xx task.name)); //task.name); TODO Fix required for LLVM/Cncurses. TODO DAM - // TODO FIXME OH MY GOD SUCH BAD CODEZ + // Print title. + // When the column is wider than the name, we end up with the trailing zeros. + // Thankfully, the trailing zeros are not printed so, it's all good. + task_name := cast(string)task.name; + task_name = truncate(task_name, column_width); TUI.set_cursor_position(x, y); - white_spaces := column_width; - // FIXME Improve by using buffer instead of printing one char at the time. - while white_spaces > 0 { - print_character(#char " "); - white_spaces -= 1; - } - TUI.set_cursor_position(x, y); - task_name: string = cast(string)task.name; - task_name.count = ifx task_name.count > column_width then column_width else task_name.count; - print("%", task_name); + write_string(task_name); + // Paint the remaining column space. + task_name_char_count := count_characters(task_name, is_null_terminated = true); + paint_remaining := string.{ column_width - task_name_char_count, empty_line.data }; + write_string(paint_remaining); + x += column_width; // Task times. |
