From 93e841b29ea567f8ddc31ce7f104dce5396a71ba Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 31 Jul 2022 16:28:08 -0400 Subject: Move cache color to an Entry struct So that more values can be added sensibly. --- cache.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'cache.c') diff --git a/cache.c b/cache.c index a125944..30ebef4 100644 --- a/cache.c +++ b/cache.c @@ -36,11 +36,13 @@ struct Node { uint id; char *key; - enum Color color; + struct Entry entry; struct Node *prev; struct Node *next; }; +static const struct Entry DefaultEntry = { .color = Default }; + static uint gen; static struct Node *head; static struct Node *tail; @@ -50,7 +52,7 @@ static struct Node *alloc(uint id, const char *key) { if (!node) err(EX_OSERR, "calloc"); node->id = id; node->key = strdup(key); - node->color = Default; + node->entry = DefaultEntry; if (!node->key) err(EX_OSERR, "strdup"); return node; } @@ -105,13 +107,13 @@ static struct Node *insert(bool touch, uint id, const char *key) { } } -void cacheInsert(bool touch, uint id, const char *key) { - insert(touch, id, key); +struct Entry *cacheInsert(bool touch, uint id, const char *key) { + return &insert(touch, id, key)->entry; } -void cacheInsertColor(bool touch, uint id, const char *key, enum Color color) { - struct Node *node = insert(touch, id, key); - if (color != Default) node->color = color; +const struct Entry *cacheGet(uint id, const char *key) { + struct Node *node = find(id, key); + return (node ? &node->entry : &DefaultEntry); } void cacheReplace(bool touch, const char *old, const char *new) { @@ -126,11 +128,6 @@ void cacheReplace(bool touch, const char *old, const char *new) { } } -enum Color cacheColor(uint id, const char *key) { - struct Node *node = find(id, key); - return (node ? node->color : Default); -} - const char *cacheComplete(struct Cursor *curs, uint id, const char *prefix) { size_t len = strlen(prefix); if (curs->gen != gen) curs->node = NULL; -- cgit 1.4.1-2-gfad0