From ccdb9570051f9a82b987bc9e007b00603bdb3d3a Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz Date: Wed, 2 Aug 2017 10:37:17 +0200 Subject: [PATCH] update lru --- ldap/servers/slapd/dn.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index 0ae3338..07502fd 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -3106,23 +3106,23 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **ndn, char **udn, int *rc) if (strcmp(dn, node->dn) == 0) { /* We found it! */ /* Update LRU */ - /* Update head to be our predecessor */ - if (t_cache->head == node) { - t_cache->head = node->prev; - } - /* Are we already the tail? */ + /* If the node is not the tail: move it */ if (t_cache->tail != node) { - if (node->next != NULL) { + /* Cut out the node */ + if (t_cache->head == node) { + /* adjust head */ + t_cache->head = node->prev; + t_cache->head->next = NULL; + } else { + /* node is neither head or tail + * so node has next and prev */ node->next->prev = node->prev; - } - if (node->prev != NULL) { node->prev->next = node->next; } + /* move the node to the tail */ node->prev = NULL; - if (t_cache->tail != NULL) { - node->next = t_cache->tail; - t_cache->tail->prev = node; - } + node->next = t_cache->tail; + t_cache->tail->prev = node; t_cache->tail = node; } -- 2.5.5