Fix llist_sorted_difference_inplace in git-pack-redundant
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Lukas Sandström committed
Nov 15, 2005 at 22:24 UTC
1a41e743c6270a24daca7309ef3d9ef74543d8ae
1 file changed
+15
-32
pack-redundant.c
+15
-32
@@ -127,38 +127,6 @@ inline struct llist_item * llist_insert_sorted_unique(struct llist *list,
127
return llist_insert_back(list, sha1);
128
}
129
130
-/* computes A\B */
131
-void llist_sorted_difference_inplace(struct llist *A,
132
- struct llist *B)
133
-{
134
- struct llist_item *prev, *a, *b, *x;
135
-
136
- prev = a = A->front;
137
- b = B->front;
138
-
139
- while (a != NULL && b != NULL) {
140
- int cmp = memcmp(a->sha1, b->sha1, 20);
141
- if (!cmp) {
142
- x = a;
143
- if (a == A->front)
144
- A->front = a->next;
145
- a = prev->next = a->next;
146
-
147
- if (a == NULL) /* end of list */
148
- A->back = prev;
149
- A->size--;
150
- free(x);
151
- b = b->next;
152
- } else
153
- if (cmp > 0)
154
- b = b->next;
155
- else {
156
- prev = a;
157
- a = a->next;
158
- }
159
- }
160
-}
161
-
130
/* returns a pointer to an item in front of sha1 */
131
inline struct llist_item * llist_sorted_remove(struct llist *list, char *sha1,
132
struct llist_item *hint)
@@ -194,6 +162,21 @@ redo_from_start:
162
return prev;
163
}
164
165
+/* computes A\B */
166
+void llist_sorted_difference_inplace(struct llist *A,
167
+ struct llist *B)
168
+{
169
+ struct llist_item *hint, *b;
170
+
171
+ hint = NULL;
172
+ b = B->front;
173
+
174
+ while (b) {
175
+ hint = llist_sorted_remove(A, b->sha1, hint);
176
+ b = b->next;
177
+ }
178
+}
179
+
180
inline struct pack_list * pack_list_insert(struct pack_list **pl,
181
struct pack_list *entry)
182
{