Browse Source
Replace the custom calls to mru.[ch] with calls to list.h. This patch is the final step in removing the mru API completely and inlining the logic. This patch leads to significant code reduction and the mru API hence, is not a useful abstraction anymore. Signed-off-by: Gargi Sharma <gs051095@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint


7 changed files with 17 additions and 86 deletions
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
#include "cache.h" |
||||
#include "mru.h" |
||||
|
||||
void mru_append(struct mru *head, void *item) |
||||
{ |
||||
struct mru *cur = xmalloc(sizeof(*cur)); |
||||
cur->item = item; |
||||
list_add_tail(&cur->list, &head->list); |
||||
} |
||||
|
||||
void mru_mark(struct mru *head, struct mru *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 *head) |
||||
{ |
||||
struct list_head *pos; |
||||
struct list_head *tmp; |
||||
|
||||
list_for_each_safe(pos, tmp, &head->list) { |
||||
free(list_entry(pos, struct mru, list)); |
||||
} |
||||
INIT_LIST_HEAD(&head->list); |
||||
} |
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
#ifndef MRU_H |
||||
#define MRU_H |
||||
|
||||
#include "list.h" |
||||
|
||||
/** |
||||
* A simple most-recently-used cache, backed by a doubly-linked list. |
||||
* |
||||
* Usage is roughly: |
||||
* |
||||
* // Create a list. Zero-initialization is required. |
||||
* static struct mru cache; |
||||
* INIT_LIST_HEAD(&cache.list); |
||||
* |
||||
* // 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, item); |
||||
* |
||||
* // Reset the list to empty, cleaning up all resources. |
||||
* mru_clear(&cache); |
||||
* |
||||
* Note that you SHOULD NOT call mru_mark() and then continue traversing the |
||||
* list; it reorders the marked item to the front of the list, and therefore |
||||
* you will begin traversing the whole list again. |
||||
*/ |
||||
|
||||
struct mru { |
||||
struct list_head list; |
||||
void *item; |
||||
}; |
||||
|
||||
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 */ |
Loading…
Reference in new issue