From 58219552753d2c4d5e8214196b918c95d48f7d5b Mon Sep 17 00:00:00 2001 From: dam Date: Fri, 25 Nov 2022 00:26:33 +0000 Subject: Improved comments. --- main.c | 7 ++++--- readme.md | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index d1a66fc..5112448 100644 --- a/main.c +++ b/main.c @@ -54,7 +54,7 @@ typedef struct { typedef struct { task_st *tasks; size_t count; // Will always be equal or less than capacity. - size_t capacity; // Limited to PTRDIFF_MAX. + size_t capacity; // Will always be equal or less than PTRDIFF_MAX (see MAX_DATABASE_TASKS). ptrdiff_t active_task; // Will always be less than capacity/count. ptrdiff_t selected_task; // Will always be less than capacity/count. int64_t modified_on; @@ -288,8 +288,9 @@ bool create_task(database_st *db, task_st **task) { // If necessary, expand database capacity. size_t current_capacity = db->capacity; if((db->count + 1) > current_capacity) { - size_t new_capacity = current_capacity == 0 ? 2 : - current_capacity > MAX_DATABASE_TASKS >> 1 ? MAX_DATABASE_TASKS : + size_t new_capacity = + current_capacity == 0 ? 2 : + current_capacity > (MAX_DATABASE_TASKS >> 1) ? MAX_DATABASE_TASKS : current_capacity << 1; task_st *new_tasks = realloc(db->tasks, new_capacity * SIZEOF_TASK_ST); diff --git a/readme.md b/readme.md index 5c76d63..264c790 100644 --- a/readme.md +++ b/readme.md @@ -41,7 +41,8 @@ Task Time Tracker - [x] Check if next/previous is safe against overflows/underflows using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html - [x] Confirm delete_task operation by show confirmation message on selected line (horizontally centered). - [x] Check totals update speedup using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html - - For 1M entries, generic C code runs in 12.0ms while special approaches using builtins or SIMD takes around 9.5ms. Not worth the effort. + - For 1M entries, generic C code runs in 12.0ms while special approaches using builtins or SIMD takes around 9.5ms. + - Used optimization described [here](https://stackoverflow.com/questions/17580118/signed-saturated-add-of-64-bit-ints). - [x] Allow to jump to specific task by index number using key `g` and `G`; - [x] Move task to (using task_t tmp_task + memcpy) using key `m` and `M`; - [x] Rethink keys; -- cgit v1.2.3