提交 60435f68 编写于 作者: A Alex Riesen 提交者: Junio C Hamano

speedup allocation in pack-redundant.c

Reuse discarded nodes of llists
Signed-off-by: NAlex Riesen <ariesen@harmanbecker.com>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 bb931cf9
...@@ -36,11 +36,31 @@ struct pll { ...@@ -36,11 +36,31 @@ struct pll {
size_t pl_size; size_t pl_size;
}; };
static inline void llist_free(struct llist *list) static struct llist_item *free_nodes = NULL;
static inline struct llist_item *llist_item_get()
{
struct llist_item *new;
if ( free_nodes ) {
new = free_nodes;
free_nodes = free_nodes->next;
} else
new = xmalloc(sizeof(struct llist_item));
return new;
}
static inline void llist_item_put(struct llist_item *item)
{
item->next = free_nodes;
free_nodes = item;
}
static void llist_free(struct llist *list)
{ {
while((list->back = list->front)) { while((list->back = list->front)) {
list->front = list->front->next; list->front = list->front->next;
free(list->back); llist_item_put(list->back);
} }
free(list); free(list);
} }
...@@ -62,13 +82,13 @@ static struct llist * llist_copy(struct llist *list) ...@@ -62,13 +82,13 @@ static struct llist * llist_copy(struct llist *list)
if ((ret->size = list->size) == 0) if ((ret->size = list->size) == 0)
return ret; return ret;
new = ret->front = xmalloc(sizeof(struct llist_item)); new = ret->front = llist_item_get();
new->sha1 = list->front->sha1; new->sha1 = list->front->sha1;
old = list->front->next; old = list->front->next;
while (old) { while (old) {
prev = new; prev = new;
new = xmalloc(sizeof(struct llist_item)); new = llist_item_get();
prev->next = new; prev->next = new;
new->sha1 = old->sha1; new->sha1 = old->sha1;
old = old->next; old = old->next;
...@@ -82,7 +102,7 @@ static struct llist * llist_copy(struct llist *list) ...@@ -82,7 +102,7 @@ static struct llist * llist_copy(struct llist *list)
static inline struct llist_item * llist_insert(struct llist *list, static inline struct llist_item * llist_insert(struct llist *list,
struct llist_item *after, char *sha1) struct llist_item *after, char *sha1)
{ {
struct llist_item *new = xmalloc(sizeof(struct llist_item)); struct llist_item *new = llist_item_get();
new->sha1 = sha1; new->sha1 = sha1;
new->next = NULL; new->next = NULL;
...@@ -153,7 +173,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, char * ...@@ -153,7 +173,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, char *
prev->next = l->next; prev->next = l->next;
if (l == list->back) if (l == list->back)
list->back = prev; list->back = prev;
free(l); llist_item_put(l);
list->size--; list->size--;
return prev; return prev;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册