summaryrefslogtreecommitdiff
path: root/mru.c
diff options
context:
space:
mode:
Diffstat (limited to 'mru.c')
-rw-r--r--mru.c49
1 files changed, 13 insertions, 36 deletions
diff --git a/mru.c b/mru.c
index 9dedae0287..8f3f34c5ba 100644
--- a/mru.c
+++ b/mru.c
@@ -1,50 +1,27 @@
#include "cache.h"
#include "mru.h"
-void mru_append(struct mru *mru, void *item)
+void mru_append(struct mru *head, void *item)
{
- struct mru_entry *cur = xmalloc(sizeof(*cur));
+ struct mru *cur = xmalloc(sizeof(*cur));
cur->item = item;
- cur->prev = mru->tail;
- cur->next = NULL;
-
- if (mru->tail)
- mru->tail->next = cur;
- else
- mru->head = cur;
- mru->tail = cur;
+ list_add_tail(&cur->list, &head->list);
}
-void mru_mark(struct mru *mru, struct mru_entry *entry)
+void mru_mark(struct mru *head, struct mru *entry)
{
- /* If we're already at the front of the list, nothing to do */
- if (mru->head == entry)
- return;
-
- /* Otherwise, remove us from our current slot... */
- if (entry->prev)
- entry->prev->next = entry->next;
- if (entry->next)
- entry->next->prev = entry->prev;
- else
- mru->tail = entry->prev;
-
- /* And insert us at the beginning. */
- entry->prev = NULL;
- entry->next = mru->head;
- if (mru->head)
- mru->head->prev = entry;
- mru->head = entry;
+ /* To mark means to put at the front of the list. */
+ list_del(&entry->list);
+ list_add(&entry->list, &head->list);
}
-void mru_clear(struct mru *mru)
+void mru_clear(struct mru *head)
{
- struct mru_entry *p = mru->head;
+ struct list_head *pos;
+ struct list_head *tmp;
- while (p) {
- struct mru_entry *to_free = p;
- p = p->next;
- free(to_free);
+ list_for_each_safe(pos, tmp, &head->list) {
+ free(list_entry(pos, struct mru, list));
}
- mru->head = mru->tail = NULL;
+ INIT_LIST_HEAD(&head->list);
}