summaryrefslogtreecommitdiff
path: root/src/llist.h
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-09-28 16:13:17 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-10-05 12:25:48 +0200
commita0afb7ded2fba68e710afda1053dba2a20b4665f (patch)
tree3592e3b3def25a654a44790e41ca800946a3bcc4 /src/llist.h
parent718a6cfee4916f347636215ee35313610793f9bd (diff)
downloadcalcurse-a0afb7ded2fba68e710afda1053dba2a20b4665f.zip
src/llist.c: Add a tail pointer
Adding a tail pointer to each list increases memory footprint by four bytes, while reducing the runtime of llist_add() from O(n) to O(1). In testing, the time required to append 100000 elements to a linked list was reduced from 29.245s to 0.009s. Our second main concern is to reduce the runtime of llist_add_sorted() when inserting elements from a presorted list (this is reduced from O(n) to O(1) as well), since the data files contain appointments in sorted order and are always processed front to back. Some local numbers show how this speeds up calcurse startup (test set with 50000 appointments): 0.22user 0.12system 0:00.35elapsed 99%CPU (0avgtext+0avgdata 5396maxresident)k 0inputs+8outputs (0major+1398minor)pagefaults 0swaps As opposed to the unpatched binary: 21.97user 0.25system 0:22.23elapsed 99%CPU (0avgtext+0avgdata 5388maxresident)k 0inputs+48outputs (0major+1396minor)pagefaults 0swaps This is a ~10000% increase in speed. Timings for reading random input files generated by a script stay the same (32.391s vs. 31.776s). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/llist.h')
-rw-r--r--src/llist.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/llist.h b/src/llist.h
index d7e4249..cdab18d 100644
--- a/src/llist.h
+++ b/src/llist.h
@@ -44,6 +44,7 @@ struct llist_item {
typedef struct llist llist_t;
struct llist {
struct llist_item *head;
+ struct llist_item *tail;
};
typedef int (*llist_fn_cmp_t) (void *, void *);