Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mru.c
diff options
context:
space:
mode:
authorOlga Telezhnaya <olyatelezhnaya@gmail.com>2017-09-30 20:51:01 +0300
committerJunio C Hamano <gitster@pobox.com>2017-10-01 11:30:26 +0300
commit8865859dfc346c61f0e75fa429c5d307bd27368c (patch)
tree81b8f55f9ca4f3e4c523a5f2072feccf792e176e /mru.c
parent20fed7cad40ed0b96232feb828129e3a2ee9860d (diff)
mru: use double-linked list from list.h
Simplify mru.[ch] and related code by reusing the double-linked list implementation from list.h instead of a custom one. This commit is an intermediate step. Our final goal is to get rid of mru.[ch] at all and inline all logic. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored by: Jeff King <peff@peff.net> Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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);
}