summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bb931cf)
raw | patch | inline | side by side (parent: bb931cf)
author | Alex Riesen <raa.lkml@gmail.com> | |
Tue, 22 Nov 2005 14:56:35 +0000 (15:56 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 22 Nov 2005 20:38:21 +0000 (12:38 -0800) |
Reuse discarded nodes of llists
Signed-off-by: Alex Riesen <ariesen@harmanbecker.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Alex Riesen <ariesen@harmanbecker.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
pack-redundant.c | patch | blob | history |
diff --git a/pack-redundant.c b/pack-redundant.c
index 9851c297279287fbc84a8abd2865775644b1315e..3b91838c453ec82df38203ba9c004fb7ceeb70f7 100644 (file)
--- a/pack-redundant.c
+++ b/pack-redundant.c
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)) {
list->front = list->front->next;
- free(list->back);
+ llist_item_put(list->back);
}
free(list);
}
if ((ret->size = list->size) == 0)
return ret;
- new = ret->front = xmalloc(sizeof(struct llist_item));
+ new = ret->front = llist_item_get();
new->sha1 = list->front->sha1;
old = list->front->next;
while (old) {
prev = new;
- new = xmalloc(sizeof(struct llist_item));
+ new = llist_item_get();
prev->next = new;
new->sha1 = old->sha1;
old = old->next;
static inline struct llist_item * llist_insert(struct llist *list,
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->next = NULL;
prev->next = l->next;
if (l == list->back)
list->back = prev;
- free(l);
+ llist_item_put(l);
list->size--;
return prev;
}