# HG changeset patch # User Dan Winship # Date 1203106118 18000 # Node ID feef7736a439674b6eb86d0ab37c082ea267a3e2 # Parent 4e699bd39b4070f92a70b48fde1ecdccfc44cfae misc fixes for edge cases 1) sets with only one package 2) packages with only one property 3) sets with only one property diff -r 4e699bd39b40 -r feef7736a439 razor.c --- a/razor.c Fri Feb 15 09:31:20 2008 -0500 +++ b/razor.c Fri Feb 15 15:08:38 2008 -0500 @@ -248,7 +248,8 @@ { list_set_array(&importer->package->properties, &importer->set->property_pool, - &importer->properties); + &importer->properties, + 1); array_release(&importer->properties); } @@ -510,11 +511,12 @@ } free(map); - up++; + if (up != rp) + up++; set->properties.size = (void *) up - set->properties.data; rp_end = up; for (rp = set->properties.data, p = pkgs; rp < rp_end; rp++, p++) { - list_set_array(&rp->packages, &set->package_pool, p); + list_set_array(&rp->packages, &set->package_pool, p, 0); array_release(p); } @@ -565,7 +567,7 @@ e->start = p->count > 0 ? s : 0; s += p->count; - list_set_array(&e->packages, &set->package_pool, &p->packages); + list_set_array(&e->packages, &set->package_pool, &p->packages, 0); array_release(&p->packages); p++; } @@ -687,7 +689,7 @@ packages = set->packages.data; for (i = 0; i < count; i++) { - list_set_array(&packages[i].files, &set->file_pool, &pkgs[i]); + list_set_array(&packages[i].files, &set->file_pool, &pkgs[i], 0); array_release(&pkgs[i]); } free(pkgs); @@ -1210,12 +1212,16 @@ send = source1->set->packages.data + source1->set->packages.size; spool = source1->set->string_pool.data; - while (s < send) { + while (s < send || u < uend) { p = upstream_packages + *u; - if (u < uend) + if (s < send && u < uend) cmp = strcmp(&spool[s->name], &upool[p->name]); - if (u >= uend || cmp < 0) { + else if (s < send) + cmp = -1; + else + cmp = 1; + if (cmp < 0) { add_package(merger, s, source1, 0); s++; } else if (cmp == 0) { @@ -1364,7 +1370,7 @@ prop_end = set->properties.data + set->properties.size; a = pkgs; for (prop = set->properties.data; prop < prop_end; prop++, a++) { - list_set_array(&prop->packages, pool, a); + list_set_array(&prop->packages, pool, a, 0); array_release(a); } free(pkgs); diff -r 4e699bd39b40 -r feef7736a439 types.c --- a/types.c Fri Feb 15 09:31:20 2008 -0500 +++ b/types.c Fri Feb 15 15:08:38 2008 -0500 @@ -63,21 +63,26 @@ } void -list_set_array(struct list_head *head, struct array *pool, struct array *items) +list_set_array(struct list_head *head, struct array *pool, + struct array *items, int force_indirect) { struct list *p; - if (items->size == 0) { - list_set_empty(head); - } else if (items->size == sizeof (uint32_t)) { - head->list_ptr = *(uint32_t *) items->data; - head->flags = RAZOR_IMMEDIATE; - } else { - p = array_add(pool, items->size); - memcpy(p, items->data, items->size); - p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST; - list_set_ptr(head, p - (struct list *) pool->data); + if (!force_indirect) { + if (items->size == 0) { + list_set_empty(head); + return; + } else if (items->size == sizeof (uint32_t)) { + head->list_ptr = *(uint32_t *) items->data; + head->flags = RAZOR_IMMEDIATE; + return; + } } + + p = array_add(pool, items->size); + memcpy(p, items->data, items->size); + p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST; + list_set_ptr(head, p - (struct list *) pool->data); } struct list * diff -r 4e699bd39b40 -r feef7736a439 types.h --- a/types.h Fri Feb 15 09:31:20 2008 -0500 +++ b/types.h Fri Feb 15 15:08:38 2008 -0500 @@ -25,7 +25,7 @@ void list_set_empty(struct list_head *head); void list_set_ptr(struct list_head *head, uint32_t ptr); -void list_set_array(struct list_head *head, struct array *pool, struct array *items); +void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect); struct list *list_first(struct list_head *head, struct array *pool); struct list *list_next(struct list *list);