summaryrefslogtreecommitdiff
path: root/mru.h
diff options
context:
space:
mode:
authorLibravatar Olga Telezhnaya <olyatelezhnaya@gmail.com>2017-09-30 17:51:01 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-10-01 17:30:26 +0900
commit8865859dfc346c61f0e75fa429c5d307bd27368c (patch)
tree81b8f55f9ca4f3e4c523a5f2072feccf792e176e /mru.h
parentThe tenth batch for 2.15 (diff)
downloadtgif-8865859dfc346c61f0e75fa429c5d307bd27368c.tar.xz
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.h')
-rw-r--r--mru.h31
1 files changed, 13 insertions, 18 deletions
diff --git a/mru.h b/mru.h
index 42e4aeaa10..80a589eb4c 100644
--- a/mru.h
+++ b/mru.h
@@ -1,6 +1,8 @@
#ifndef MRU_H
#define MRU_H
+#include "list.h"
+
/**
* A simple most-recently-used cache, backed by a doubly-linked list.
*
@@ -8,18 +10,15 @@
*
* // Create a list. Zero-initialization is required.
* static struct mru cache;
- * mru_append(&cache, item);
- * ...
+ * INIT_LIST_HEAD(&cache.list);
*
- * // Iterate in MRU order.
- * struct mru_entry *p;
- * for (p = cache.head; p; p = p->next) {
- * if (matches(p->item))
- * break;
- * }
+ * // Add new item to the end of the list.
+ * void *item;
+ * ...
+ * mru_append(&cache, item);
*
* // Mark an item as used, moving it to the front of the list.
- * mru_mark(&cache, p);
+ * mru_mark(&cache, item);
*
* // Reset the list to empty, cleaning up all resources.
* mru_clear(&cache);
@@ -29,17 +28,13 @@
* you will begin traversing the whole list again.
*/
-struct mru_entry {
- void *item;
- struct mru_entry *prev, *next;
-};
-
struct mru {
- struct mru_entry *head, *tail;
+ struct list_head list;
+ void *item;
};
-void mru_append(struct mru *mru, void *item);
-void mru_mark(struct mru *mru, struct mru_entry *entry);
-void mru_clear(struct mru *mru);
+void mru_append(struct mru *head, void *item);
+void mru_mark(struct mru *head, struct mru *entry);
+void mru_clear(struct mru *head);
#endif /* MRU_H */