about summary refs log tree commit diff
path: root/cache.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-07-31 16:28:08 -0400
committerJune McEnroe <june@causal.agency>2022-07-31 18:17:08 -0400
commit93e841b29ea567f8ddc31ce7f104dce5396a71ba (patch)
tree9d844670e8e88af199410f66c7c2e90a91233bcb /cache.c
parentOnly set cache color if not Default (diff)
downloadcatgirl-93e841b29ea567f8ddc31ce7f104dce5396a71ba.tar.gz
catgirl-93e841b29ea567f8ddc31ce7f104dce5396a71ba.zip
Move cache color to an Entry struct
So that more values can be added sensibly.
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c21
1 files changed, 9 insertions, 12 deletions
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;