From a84c0f57b5efde85c195cbc706715bf4a4116018 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Mon, 15 Mar 2021 02:39:41 +0200 Subject: cleanup and optimizations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · No longer rewinding a stream being split, just to skip half through it again, which was not only stupid, but inneficient. · No longer using "index" anywhere when working with lists, lest we get accused of not actually doing lists. Signed-off-by: Gediminas Jakutis --- src/cache.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/cache.c') diff --git a/src/cache.c b/src/cache.c index 2b24dd0..3a169b8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -122,10 +122,9 @@ struct entry_l *cached_get_list(struct stream * const in, struct entry_l * const { struct entry_l *ret = NULL; - if (in->index < in->n) { + if (in->cnode) { ret = in->cnode; - in->cnode = ret->next ? ret->next : in->cnode; - ++in->index; + in->cnode = ret->next; *store = *ret; ret = store; } @@ -163,17 +162,14 @@ int cached_put_list(struct stream * const restrict in, const struct entry_l * co if (!in->cnode) { /* if this is the very first one */ in->cnode = in->cache_l; - in->cnode->val = node->val; - in->cnode->next = NULL; - in->index = 1; } else { in->cnode->next = in->cnode + 1; /* lol says librin, lmao */ in->cnode = in->cnode->next; - in->cnode->val = node->val; - in->cnode->next = NULL; - ++in->index; } + in->cnode->val = node->val; + in->cnode->next = NULL; + err: return ret; } -- cgit v1.2.3