diff options
author | pommicket <pommicket@gmail.com> | 2022-12-31 10:41:01 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-31 10:41:24 -0500 |
commit | 31520dd979ef8abe4e38d4ba0b2912a8385b8351 (patch) | |
tree | 4a19d083e416741a6b52fdbfda6166ec1773a021 | |
parent | 2b3b1bd0ed03739e3357516490e265261c5f815f (diff) |
avoid using time_get_seconds
because it makes a syscall
-rw-r--r-- | buffer.c | 8 | ||||
-rw-r--r-- | command.c | 6 | ||||
-rw-r--r-- | ide-autocomplete.c | 2 | ||||
-rw-r--r-- | ide-usages.c | 2 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | ted.c | 2 |
6 files changed, 13 insertions, 15 deletions
@@ -606,7 +606,7 @@ void buffer_check_valid(TextBuffer *buffer) { #endif static Status buffer_edit_create(TextBuffer *buffer, BufferEdit *edit, BufferPos start, u32 prev_len, u32 new_len) { - edit->time = time_get_seconds(); + edit->time = buffer->ted->frame_time; if (prev_len == 0) edit->prev_text = NULL; // if there's no previous text, don't allocate anything else @@ -699,7 +699,7 @@ static bool buffer_edit_split(TextBuffer *buffer) { if (!last_edit) return true; if (buffer->will_chain_edits) return true; if (buffer->chaining_edits) return false; - double curr_time = time_get_seconds(); + double curr_time = buffer->ted->frame_time; double undo_time_cutoff = buffer_settings(buffer)->undo_save_time; // only keep around edits for this long (in seconds). return last_edit->time <= buffer->last_write_time // last edit happened before buffer write (we need to split this so that undo_history_write_pos works) || curr_time - last_edit->time > undo_time_cutoff; @@ -2815,12 +2815,12 @@ void buffer_render(TextBuffer *buffer, Rect r) { float time_on = settings->cursor_blink_time_on; float time_off = settings->cursor_blink_time_off; double error_animation_duration = 1.0; - double error_animation_dt = time_get_seconds() - ted->cursor_error_time; + double error_animation_dt = ted->frame_time - ted->cursor_error_time; bool error_animation = ted->cursor_error_time > 0 && error_animation_dt < error_animation_duration; bool is_on = true; if (!error_animation && time_off > 0) { - double absolute_time = time_get_seconds(); + double absolute_time = ted->frame_time; float period = time_on + time_off; // time in period double t = fmod(absolute_time, period); @@ -224,7 +224,7 @@ void command_execute(Ted *ted, Command c, i64 argument) { ted_new_file(ted, NULL); break; case CMD_SAVE: - ted->last_save_time = time_get_seconds(); + ted->last_save_time = ted->frame_time; if (buffer) { if (buffer_is_untitled(buffer)) { command_execute(ted, CMD_SAVE_AS, 1); @@ -234,13 +234,13 @@ void command_execute(Ted *ted, Command c, i64 argument) { } break; case CMD_SAVE_AS: - ted->last_save_time = time_get_seconds(); + ted->last_save_time = ted->frame_time; if (buffer && !buffer->is_line_buffer) { menu_open(ted, MENU_SAVE_AS); } break; case CMD_SAVE_ALL: - ted->last_save_time = time_get_seconds(); + ted->last_save_time = ted->frame_time; ted_save_all(ted); break; case CMD_RELOAD_ALL: diff --git a/ide-autocomplete.c b/ide-autocomplete.c index 47b238f..e5dd848 100644 --- a/ide-autocomplete.c +++ b/ide-autocomplete.c @@ -102,7 +102,7 @@ static bool autocomplete_using_lsp(Ted *ted) { static void autocomplete_no_suggestions(Ted *ted) { Autocomplete *ac = &ted->autocomplete; if (ac->trigger == TRIGGER_INVOKED) - ted->cursor_error_time = time_get_seconds(); + ted_flash_error_cursor(ted); autocomplete_close(ted); } diff --git a/ide-usages.c b/ide-usages.c index dccb3d0..9b1b3fb 100644 --- a/ide-usages.c +++ b/ide-usages.c @@ -56,7 +56,7 @@ void usages_process_lsp_response(Ted *ted, LSPResponse *response) { build_check_for_errors(ted); } else { - ted->cursor_error_time = time_get_seconds(); + ted_flash_error_cursor(ted); } usages->last_request_id = 0; } @@ -1,7 +1,6 @@ /* @TODO: - show line containing usage -- change frame_time to a double - highlight-enabled, and highlight-auto - handle multiple symbols with same name in go-to-definition menu - :go-to-cursor-definition @@ -951,7 +950,7 @@ int main(int argc, char **argv) { glUseProgram(shader); if (array) glBindVertexArray(array); - double t = time_get_seconds(); + double t = ted->frame_time; glUniform1f(glGetUniformLocation(shader, "t_time"), (float)fmod(t - start_time, 3600)); glUniform2f(glGetUniformLocation(shader, "t_aspect"), (float)window_width / (float)window_height, 1); glUniform1f(glGetUniformLocation(shader, "t_save_time"), (float)(t - ted->last_save_time)); @@ -1065,7 +1064,7 @@ int main(int argc, char **argv) { // check if there's a new error if (ted_haserr(ted)) { - ted->error_time = time_get_seconds(); + ted->error_time = ted->frame_time; str_cpy(ted->error_shown, sizeof ted->error_shown, ted->error); { // output error to log file @@ -1083,8 +1082,7 @@ int main(int argc, char **argv) { // error box if (*ted->error_shown) { - double t = time_get_seconds(); - double time_passed = t - ted->error_time; + double time_passed = ted->frame_time - ted->error_time; Settings *settings = ted_active_settings(ted); if (time_passed > settings->error_display_time) { // stop showing error @@ -536,7 +536,7 @@ bool ted_get_mouse_buffer_pos(Ted *ted, TextBuffer **pbuffer, BufferPos *ppos) { // make the cursor red for a bit to indicate an error (e.g. no autocompletions) void ted_flash_error_cursor(Ted *ted) { - ted->cursor_error_time = time_get_seconds(); + ted->cursor_error_time = ted->frame_time; } void ted_go_to_position(Ted *ted, const char *path, u32 line, u32 index, bool is_lsp) { |