git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Lukas Sandström" <lukass@etek.chalmers.se>
To: junkio@cox.net
Cc: "Alex Riesen" <raa.lkml@gmail.com>,
	git@vger.kernel.org, "Lukas Sandström" <lukass@etek.chalmers.se>
Subject: [PATCH] Fix llist_sorted_difference_inplace in git-pack-redundant
Date: Tue, 15 Nov 2005 22:24:02 +0100	[thread overview]
Message-ID: <437A51F2.4000106@etek.chalmers.se> (raw)
In-Reply-To: <81b0412b0511150749g5672158v7b39c02ffdf13e08@mail.gmail.com>

Simplify and actually make llist_sorted_difference_inplace work
by using llist_sorted_remove instead of duplicating parts of the
code.

Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>

---
Looking at the code; I must have been tired when I wrote llist_sorted_difference_inplace.
This should hopefully fix things up nicely. Note that I think the old version got the
case "remove last element from list" wrong too.

I think the Signed-off line is in utf8 this time. Tell me if it works better, of if I 
just should change my name ;)

 pack-redundant.c |   47 +++++++++++++++--------------------------------
 1 files changed, 15 insertions(+), 32 deletions(-)

applies-to: 4b6dbe856a3e63699b299c76f4f1fc5cb34cbe26
560aa97889ef028fed0678389d4bb05ebf3ead62
diff --git a/pack-redundant.c b/pack-redundant.c
index 28b82ee..fcb36ff 100644
--- a/pack-redundant.c
+++ b/pack-redundant.c
@@ -127,38 +127,6 @@ inline struct llist_item * llist_insert_
 	return llist_insert_back(list, sha1);
 }
 
-/* computes A\B */
-void llist_sorted_difference_inplace(struct llist *A,
-				     struct llist *B)
-{
-	struct llist_item *prev, *a, *b, *x;
-
-	prev = a = A->front;
-	b = B->front;
-
-	while (a != NULL && b != NULL) {
-		int cmp = memcmp(a->sha1, b->sha1, 20);
-		if (!cmp) {
-			x = a;
-			if (a == A->front)
-				A->front = a->next;
-			a = prev->next = a->next;
-
-			if (a == NULL) /* end of list */
-				A->back = prev;
-			A->size--;
-			free(x);
-			b = b->next;
-		} else
-			if (cmp > 0)
-				b = b->next;
-			else {
-				prev = a;
-				a = a->next;
-			}
-	}
-}
-
 /* returns a pointer to an item in front of sha1 */
 inline struct llist_item * llist_sorted_remove(struct llist *list, char *sha1,
 					       struct llist_item *hint)
@@ -194,6 +162,21 @@ redo_from_start:
 	return prev;
 }
 
+/* computes A\B */
+void llist_sorted_difference_inplace(struct llist *A,
+				     struct llist *B)
+{
+	struct llist_item *hint, *b;
+
+	hint = NULL;
+	b = B->front;
+
+	while (b) {
+		hint = llist_sorted_remove(A, b->sha1, hint);
+		b = b->next;
+	}
+}
+
 inline struct pack_list * pack_list_insert(struct pack_list **pl,
 					   struct pack_list *entry)
 {
---
0.99.9.GIT

  parent reply	other threads:[~2005-11-15 21:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-16 23:09 git-pack-redundant returns the most containing pack Alex Riesen
2005-11-16 23:23 ` Lukas Sandström
2005-11-15 15:49   ` fix git-pack-redundant crashing sometimes Alex Riesen
2005-11-15 16:08     ` Timo Hirvonen
2005-11-15 16:11       ` Alex Riesen
2005-11-15 17:28         ` Linus Torvalds
2005-11-15 21:38       ` Lukas Sandström
2005-11-15 21:24     ` Lukas Sandström [this message]
2005-11-15 21:34     ` Alex Riesen
2005-11-15 21:41       ` Lukas Sandström
2005-11-15 22:33         ` Alex Riesen
2005-11-15 23:13           ` Lukas Sandström
2005-11-16  7:01             ` Alex Riesen
2005-11-16 21:11             ` Alex Riesen
2005-11-15 23:58           ` Linus Torvalds
2005-11-16 20:13             ` Junio C Hamano
2005-11-16 21:37             ` Lukas Sandström
2005-11-16 23:59               ` Lukas Sandström
2005-11-17 16:56                 ` Matthias Urlichs
2005-11-17  7:08               ` Fredrik Kuivinen
2005-11-17 13:11           ` [PATCH] Make git-pack-redundant non-horribly slow on large sets of packs Lukas Sandström
2005-11-17 20:39             ` Alex Riesen
2005-11-18 16:30             ` [PATCH] Fix bug introduced by the latest changes to git-pack-redundant Lukas Sandström
2005-11-18 21:53             ` [PATCH] Fix a bug in get_all_permutations Lukas Sandström
2005-11-17  7:45   ` git-pack-redundant returns the most containing pack Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=437A51F2.4000106@etek.chalmers.se \
    --to=lukass@etek.chalmers.se \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).