aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-11-25 00:26:33 +0000
committerdam <dam@gudinoff>2022-11-25 00:26:33 +0000
commit58219552753d2c4d5e8214196b918c95d48f7d5b (patch)
tree56fb3a29049c03984fa0d178b37063655ffd3406
parentd808a8c3af7a048d3d186cf10a8122e8d3ffc6bc (diff)
downloadtask-time-tracker-58219552753d2c4d5e8214196b918c95d48f7d5b.tar.zst
task-time-tracker-58219552753d2c4d5e8214196b918c95d48f7d5b.zip
Improved comments.
-rw-r--r--main.c7
-rw-r--r--readme.md3
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;