1.1 --- a/razor.c Thu Feb 07 09:58:48 2008 -0500
1.2 +++ b/razor.c Fri Feb 08 11:19:36 2008 -0500
1.3 @@ -34,7 +34,6 @@
1.4 #define RAZOR_VERSION 1
1.5
1.6 #define RAZOR_ENTRY_LAST 0x80000000ul
1.7 -#define RAZOR_IMMEDIATE 0x80000000ul
1.8 #define RAZOR_ENTRY_MASK 0x00fffffful
1.9
1.10 #define RAZOR_STRING_POOL 0
1.11 @@ -226,23 +225,6 @@
1.12 return 0;
1.13 }
1.14
1.15 -static uint32_t
1.16 -add_to_property_pool(struct array *pool, struct array *properties)
1.17 -{
1.18 - uint32_t *p;
1.19 -
1.20 - if (properties->size == 0)
1.21 - return ~0;
1.22 - else if (properties->size == sizeof *p)
1.23 - return *(uint32_t *) properties->data | RAZOR_IMMEDIATE;
1.24 -
1.25 - p = array_add(pool, properties->size);
1.26 - memcpy(p, properties->data, properties->size);
1.27 - p[properties->size / sizeof *p - 1] |= RAZOR_ENTRY_LAST;
1.28 -
1.29 - return p - (uint32_t *) pool->data;
1.30 -}
1.31 -
1.32 void
1.33 razor_importer_begin_package(struct razor_importer *importer,
1.34 const char *name, const char *version)
1.35 @@ -260,9 +242,9 @@
1.36 void
1.37 razor_importer_finish_package(struct razor_importer *importer)
1.38 {
1.39 - importer->package->properties =
1.40 - add_to_property_pool(&importer->set->property_pool,
1.41 - &importer->properties);
1.42 + list_set (&importer->package->properties,
1.43 + &importer->set->property_pool,
1.44 + &importer->properties);
1.45
1.46 array_release(&importer->properties);
1.47 }
1.48 @@ -525,8 +507,7 @@
1.49 set->properties.size = (void *) up - set->properties.data;
1.50 rp_end = up;
1.51 for (rp = set->properties.data, p = pkgs; rp < rp_end; rp++, p++) {
1.52 - rp->packages =
1.53 - add_to_property_pool(&set->package_pool, p);
1.54 + list_set(&rp->packages, &set->package_pool, p);
1.55 array_release(p);
1.56 }
1.57
1.58 @@ -535,16 +516,6 @@
1.59 return rmap;
1.60 }
1.61
1.62 -static void
1.63 -remap_links(struct array *links, uint32_t *map)
1.64 -{
1.65 - uint32_t *p, *end;
1.66 -
1.67 - end = links->data + links->size;
1.68 - for (p = links->data; p < end; p++)
1.69 - *p = map[*p & RAZOR_ENTRY_MASK] | (*p & ~RAZOR_ENTRY_MASK);
1.70 -}
1.71 -
1.72 static int
1.73 compare_filenames(const void *p1, const void *p2, void *data)
1.74 {
1.75 @@ -586,8 +557,7 @@
1.76 e->start = p->count > 0 ? s : 0;
1.77 s += p->count;
1.78
1.79 - e->packages = add_to_property_pool(&set->package_pool,
1.80 - &p->packages);
1.81 + list_set(&e->packages, &set->package_pool, &p->packages);
1.82 array_release(&p->packages);
1.83 p++;
1.84 }
1.85 @@ -609,9 +579,7 @@
1.86
1.87 end = properties->data + properties->size;
1.88 for (p = properties->data; p < end; p++)
1.89 - if (p->packages & RAZOR_IMMEDIATE)
1.90 - p->packages = rmap[p->packages & RAZOR_ENTRY_MASK] |
1.91 - RAZOR_IMMEDIATE;
1.92 + list_remap_if_immediate(&p->packages, rmap);
1.93 }
1.94
1.95 static void
1.96 @@ -677,7 +645,7 @@
1.97 e = array_add(&importer->set->files, sizeof *e);
1.98 e->name = root.name | RAZOR_ENTRY_LAST;
1.99 e->start = 1;
1.100 - e->packages = ~0;
1.101 + list_init(&e->packages);
1.102
1.103 serialize_files(importer->set, &root, &importer->set->files);
1.104
1.105 @@ -698,28 +666,18 @@
1.106
1.107 end = set->files.data + set->files.size;
1.108 for (e = set->files.data; e < end; e++) {
1.109 - if (e->packages == ~0) {
1.110 - continue;
1.111 - } else if (e->packages & RAZOR_IMMEDIATE) {
1.112 - e->packages = rmap[e->packages & RAZOR_ENTRY_MASK] |
1.113 - RAZOR_IMMEDIATE;
1.114 - r = &e->packages;
1.115 - } else {
1.116 - r = (uint32_t *) set->package_pool.data + e->packages;
1.117 - }
1.118 -
1.119 - while (1) {
1.120 - q = array_add(&pkgs[*r & RAZOR_ENTRY_MASK], sizeof *q);
1.121 + list_remap_if_immediate(&e->packages, rmap);
1.122 + r = list_first(&e->packages, &set->package_pool);
1.123 + while (r) {
1.124 + q = array_add(&pkgs[LIST_VALUE(r)], sizeof *q);
1.125 *q = e - (struct razor_entry *) set->files.data;
1.126 - if (*r++ & RAZOR_IMMEDIATE)
1.127 - break;
1.128 + r = list_next(r);
1.129 }
1.130 }
1.131
1.132 packages = set->packages.data;
1.133 for (i = 0; i < count; i++) {
1.134 - packages[i].files =
1.135 - add_to_property_pool(&set->file_pool, &pkgs[i]);
1.136 + list_set(&packages[i].files, &set->file_pool, &pkgs[i]);
1.137 array_release(&pkgs[i]);
1.138 }
1.139 free(pkgs);
1.140 @@ -733,7 +691,7 @@
1.141 int i, count;
1.142
1.143 map = uniqueify_properties(importer->set);
1.144 - remap_links(&importer->set->property_pool, map);
1.145 + list_remap_pool(&importer->set->property_pool, map);
1.146 free(map);
1.147
1.148 count = importer->set->packages.size / sizeof(struct razor_package);
1.149 @@ -749,7 +707,7 @@
1.150 free(map);
1.151
1.152 build_file_tree(importer);
1.153 - remap_links(&importer->set->package_pool, rmap);
1.154 + list_remap_pool(&importer->set->package_pool, rmap);
1.155 build_package_file_lists(importer->set, rmap);
1.156 remap_property_package_links(&importer->set->properties, rmap);
1.157 free(rmap);
1.158 @@ -765,7 +723,6 @@
1.159 struct razor_set *set;
1.160 struct razor_package *package, *end;
1.161 uint32_t *index;
1.162 - int last;
1.163 };
1.164
1.165 struct razor_package_iterator *
1.166 @@ -776,8 +733,6 @@
1.167
1.168 pi = zalloc(sizeof *pi);
1.169 pi->set = set;
1.170 - pi->end = set->packages.data + set->packages.size;
1.171 - pi->package = set->packages.data;
1.172 pi->index = index;
1.173
1.174 return pi;
1.175 @@ -786,7 +741,14 @@
1.176 struct razor_package_iterator *
1.177 razor_package_iterator_create(struct razor_set *set)
1.178 {
1.179 - return razor_package_iterator_create_with_index(set, NULL);
1.180 + struct razor_package_iterator *pi;
1.181 +
1.182 + pi = zalloc(sizeof *pi);
1.183 + pi->set = set;
1.184 + pi->end = set->packages.data + set->packages.size;
1.185 + pi->package = set->packages.data;
1.186 +
1.187 + return pi;
1.188 }
1.189
1.190 struct razor_package_iterator *
1.191 @@ -795,12 +757,7 @@
1.192 {
1.193 uint32_t *index;
1.194
1.195 - if (property->packages & RAZOR_IMMEDIATE)
1.196 - index = &property->packages;
1.197 - else
1.198 - index = (uint32_t *)
1.199 - set->package_pool.data + property->packages;
1.200 -
1.201 + index = list_first(&property->packages, &set->package_pool);
1.202 return razor_package_iterator_create_with_index(set, index);
1.203 }
1.204
1.205 @@ -813,15 +770,16 @@
1.206 int valid;
1.207 struct razor_package *p, *packages;
1.208
1.209 - if (pi->index) {
1.210 - packages = pi->set->packages.data;
1.211 - p = &packages[*pi->index & RAZOR_ENTRY_MASK];
1.212 - valid = !pi->last;
1.213 - pi->last = (*pi->index++ & RAZOR_IMMEDIATE) != 0;
1.214 - } else {
1.215 + if (pi->package) {
1.216 p = pi->package++;
1.217 valid = p < pi->end;
1.218 - }
1.219 + } else if (pi->index) {
1.220 + packages = pi->set->packages.data;
1.221 + p = &packages[LIST_VALUE(pi->index)];
1.222 + pi->index = list_next(pi->index);
1.223 + valid = 1;
1.224 + } else
1.225 + valid = 0;
1.226
1.227 if (valid) {
1.228 pool = pi->set->string_pool.data;
1.229 @@ -862,7 +820,6 @@
1.230 struct razor_set *set;
1.231 struct razor_property *property, *end;
1.232 uint32_t *index;
1.233 - int last;
1.234 };
1.235
1.236 struct razor_property_iterator *
1.237 @@ -873,12 +830,14 @@
1.238
1.239 pi = zalloc(sizeof *pi);
1.240 pi->set = set;
1.241 - pi->end = set->properties.data + set->properties.size;
1.242 - pi->property = set->properties.data;
1.243
1.244 - if (package)
1.245 + if (package) {
1.246 pi->index = (uint32_t *)
1.247 set->property_pool.data + package->properties;
1.248 + } else {
1.249 + pi->property = set->properties.data;
1.250 + pi->end = set->properties.data + set->properties.size;
1.251 + }
1.252
1.253 return pi;
1.254 }
1.255 @@ -895,15 +854,16 @@
1.256 int valid;
1.257 struct razor_property *p, *properties;
1.258
1.259 - if (pi->index) {
1.260 - properties = pi->set->properties.data;
1.261 - p = &properties[*pi->index & RAZOR_ENTRY_MASK];
1.262 - valid = !pi->last;
1.263 - pi->last = (*pi->index++ & RAZOR_IMMEDIATE) != 0;
1.264 - } else {
1.265 + if (pi->property) {
1.266 p = pi->property++;
1.267 valid = p < pi->end;
1.268 - }
1.269 + } else if (pi->index) {
1.270 + properties = pi->set->properties.data;
1.271 + p = &properties[LIST_VALUE(pi->index)];
1.272 + pi->index = list_next(pi->index);
1.273 + valid = 1;
1.274 + } else
1.275 + valid = 0;
1.276
1.277 if (valid) {
1.278 pool = pi->set->string_pool.data;
1.279 @@ -1001,12 +961,7 @@
1.280 if (entry == NULL)
1.281 return NULL;
1.282
1.283 - if (entry->packages & RAZOR_IMMEDIATE)
1.284 - index = &entry->packages;
1.285 - else
1.286 - index = (uint32_t *)
1.287 - set->package_pool.data + entry->packages;
1.288 -
1.289 + index = list_first(&entry->packages, &set->package_pool);
1.290 return razor_package_iterator_create_with_index(set, index);
1.291 }
1.292
1.293 @@ -1025,13 +980,13 @@
1.294
1.295 e = entries + dir->start;
1.296 do {
1.297 - if (entries + (*r & RAZOR_ENTRY_MASK) == e) {
1.298 + if (entries + LIST_VALUE(r) == e) {
1.299 printf("%s/%s\n", prefix,
1.300 pool + (e->name & RAZOR_ENTRY_MASK));
1.301 - if (*r & RAZOR_ENTRY_LAST)
1.302 + r = list_next(r);
1.303 + if (!r)
1.304 return NULL;
1.305 - r++;
1.306 - if ((*r & RAZOR_ENTRY_MASK) >= end)
1.307 + if (LIST_VALUE(r) >= end)
1.308 return r;
1.309 }
1.310 } while (!((e++)->name & RAZOR_ENTRY_LAST));
1.311 @@ -1053,7 +1008,7 @@
1.312 next = f->start;
1.313 }
1.314
1.315 - file = *r & RAZOR_ENTRY_MASK;
1.316 + file = LIST_VALUE(r);
1.317 if (e->start <= file && file < next) {
1.318 len = strlen(prefix);
1.319 prefix[len] = '/';
1.320 @@ -1076,7 +1031,7 @@
1.321
1.322 package = razor_set_get_package(set, name);
1.323
1.324 - r = (uint32_t *) set->file_pool.data + package->files;
1.325 + r = list_first(&package->files, &set->file_pool);
1.326 end = set->files.size / sizeof (struct razor_entry);
1.327 buffer[0] = '\0';
1.328 list_package_files(set, r, set->files.data, end, buffer);
1.329 @@ -1214,15 +1169,10 @@
1.330 &pool[package->version]);
1.331 p->properties = package->properties;
1.332
1.333 - if (package->properties & RAZOR_IMMEDIATE)
1.334 - r = &package->properties;
1.335 - else
1.336 - r = (uint32_t *)
1.337 - source->set->property_pool.data + package->properties;
1.338 - while (1) {
1.339 - source->property_map[*r & RAZOR_ENTRY_MASK] = 1;
1.340 - if (*r++ & RAZOR_IMMEDIATE)
1.341 - break;
1.342 + r = list_first(&package->properties, &source->set->property_pool);
1.343 + while (r) {
1.344 + source->property_map[LIST_VALUE(r)] = 1;
1.345 + r = list_next(r);
1.346 }
1.347 }
1.348
1.349 @@ -1350,22 +1300,21 @@
1.350 }
1.351 }
1.352
1.353 -static uint32_t
1.354 -emit_properties(struct array *source_pool, uint32_t index,
1.355 +static void
1.356 +emit_properties(uint32_t *properties, struct array *source_pool,
1.357 uint32_t *map, struct array *pool)
1.358 {
1.359 uint32_t r, *p, *q;
1.360
1.361 r = pool->size / sizeof *q;
1.362 - p = (uint32_t *) source_pool->data + index;
1.363 - while (1) {
1.364 + p = list_first(properties, source_pool);
1.365 + while (p) {
1.366 q = array_add(pool, sizeof *q);
1.367 - *q = map[*p & RAZOR_ENTRY_MASK] | (*p & ~RAZOR_ENTRY_MASK);
1.368 - if (*p++ & RAZOR_ENTRY_LAST)
1.369 - break;
1.370 + *q = map[LIST_VALUE(p)] | LIST_FLAGS(p);
1.371 + p = list_next(p);
1.372 }
1.373
1.374 - return r;
1.375 + *properties = r;
1.376 }
1.377
1.378 /* Rebuild property->packages maps. We can't just remap these, as a
1.379 @@ -1378,28 +1327,28 @@
1.380 struct array *pkgs, *a;
1.381 struct razor_package *pkg, *pkg_end;
1.382 struct razor_property *prop, *prop_end;
1.383 - uint32_t *r, *q, *pool;
1.384 + struct array *pool;
1.385 + uint32_t *r, *q;
1.386 int count;
1.387
1.388 count = set->properties.size / sizeof (struct razor_property);
1.389 pkgs = zalloc(count * sizeof *pkgs);
1.390 pkg_end = set->packages.data + set->packages.size;
1.391 - pool = set->property_pool.data;
1.392 + pool = &set->property_pool;
1.393
1.394 for (pkg = set->packages.data; pkg < pkg_end; pkg++) {
1.395 - for (r = &pool[pkg->properties]; ; r++) {
1.396 - q = array_add(&pkgs[*r & RAZOR_ENTRY_MASK], sizeof *q);
1.397 + r = list_first(&pkg->properties, pool);
1.398 + while (r) {
1.399 + q = array_add(&pkgs[LIST_VALUE(r)], sizeof *q);
1.400 *q = pkg - (struct razor_package *) set->packages.data;
1.401 - if (*r & RAZOR_IMMEDIATE)
1.402 - break;
1.403 + r = list_next(r);
1.404 }
1.405 }
1.406
1.407 prop_end = set->properties.data + set->properties.size;
1.408 a = pkgs;
1.409 for (prop = set->properties.data; prop < prop_end; prop++, a++) {
1.410 - prop->packages =
1.411 - add_to_property_pool(&set->property_pool, a);
1.412 + list_set(&prop->packages, pool, a);
1.413 array_release(a);
1.414 }
1.415 free(pkgs);
1.416 @@ -1460,10 +1409,10 @@
1.417 else
1.418 src = &merger->source1;
1.419
1.420 - p->properties = emit_properties(&src->set->property_pool,
1.421 - p->properties,
1.422 - src->property_map,
1.423 - &merger->set->property_pool);
1.424 + emit_properties(&p->properties,
1.425 + &src->set->property_pool,
1.426 + src->property_map,
1.427 + &merger->set->property_pool);
1.428 p->name &= INDEX_MASK;
1.429 }
1.430
1.431 @@ -1478,7 +1427,8 @@
1.432 {
1.433 struct razor_property *requires, *r;
1.434 struct razor_property *p, *pend;
1.435 - uint32_t *u, *end, *pkg, *package_pool;
1.436 + uint32_t *u, *end, *pkg;
1.437 + struct array *package_pool;
1.438 char *pool, *upool;
1.439
1.440 end = unsatisfied->data + unsatisfied->size;
1.441 @@ -1488,7 +1438,7 @@
1.442 p = upstream->properties.data;
1.443 pend = upstream->properties.data + upstream->properties.size;
1.444 upool = upstream->string_pool.data;
1.445 - package_pool = upstream->package_pool.data;
1.446 + package_pool = &upstream->package_pool;
1.447
1.448 for (u = unsatisfied->data; u < end; u++) {
1.449 r = requires + *u;
1.450 @@ -1513,10 +1463,7 @@
1.451 } else {
1.452 pkg = array_add(list, sizeof *pkg);
1.453 /* We just pull in the first package that provides */
1.454 - if (p->packages & RAZOR_IMMEDIATE)
1.455 - *pkg = p->packages & RAZOR_ENTRY_MASK;
1.456 - else
1.457 - *pkg = package_pool[p->packages];
1.458 + *pkg = LIST_VALUE(list_first(&p->packages, package_pool));
1.459 }
1.460 }
1.461 }
2.1 --- a/types.c Thu Feb 07 09:58:48 2008 -0500
2.2 +++ b/types.c Fri Feb 08 11:19:36 2008 -0500
2.3 @@ -43,6 +43,69 @@
2.4 return p;
2.5 }
2.6
2.7 +#define RAZOR_ENTRY_LAST 0x80000000ul
2.8 +#define RAZOR_IMMEDIATE 0x80000000ul
2.9 +#define RAZOR_ENTRY_MASK 0x00fffffful
2.10 +
2.11 +void
2.12 +list_init(uint32_t *list)
2.13 +{
2.14 + *list = ~0;
2.15 +}
2.16 +
2.17 +void
2.18 +list_set(uint32_t *list, struct array *pool, struct array *items)
2.19 +{
2.20 + uint32_t *p;
2.21 +
2.22 + if (items->size == 0) {
2.23 + list_init(list);
2.24 + } else if (items->size == sizeof (uint32_t)) {
2.25 + *list = *(uint32_t *) items->data | RAZOR_IMMEDIATE;
2.26 + } else {
2.27 + p = array_add(pool, items->size);
2.28 + memcpy(p, items->data, items->size);
2.29 + p[items->size / sizeof *p - 1] |= RAZOR_ENTRY_LAST;
2.30 + *list = p - (uint32_t *) pool->data;
2.31 + }
2.32 +}
2.33 +
2.34 +uint32_t *
2.35 +list_first(uint32_t *list, struct array *pool)
2.36 +{
2.37 + if (*list == ~0)
2.38 + return NULL;
2.39 + else if (*list & RAZOR_IMMEDIATE)
2.40 + return list;
2.41 + else
2.42 + return (uint32_t *) pool->data + (*list & RAZOR_ENTRY_MASK);
2.43 +}
2.44 +
2.45 +uint32_t *
2.46 +list_next(uint32_t *list)
2.47 +{
2.48 + if (*list & ~RAZOR_ENTRY_MASK)
2.49 + return NULL;
2.50 + return ++list;
2.51 +}
2.52 +
2.53 +void
2.54 +list_remap_pool(struct array *pool, uint32_t *map)
2.55 +{
2.56 + uint32_t *p, *end;
2.57 +
2.58 + end = pool->data + pool->size;
2.59 + for (p = pool->data; p < end; p++)
2.60 + *p = map[LIST_VALUE(p)] | LIST_FLAGS(p);
2.61 +}
2.62 +
2.63 +void
2.64 +list_remap_if_immediate(uint32_t *list, uint32_t *map)
2.65 +{
2.66 + if ((*list & ~RAZOR_ENTRY_MASK) == RAZOR_IMMEDIATE)
2.67 + *list = map[LIST_VALUE(list)] | LIST_FLAGS(list);
2.68 +}
2.69 +
2.70
2.71 void
2.72 hashtable_init(struct hashtable *table, struct array *pool)
3.1 --- a/types.h Thu Feb 07 09:58:48 2008 -0500
3.2 +++ b/types.h Fri Feb 08 11:19:36 2008 -0500
3.3 @@ -13,6 +13,15 @@
3.4 void *array_add(struct array *array, int size);
3.5
3.6
3.7 +void list_init(uint32_t *list);
3.8 +void list_set(uint32_t *list, struct array *pool, struct array *items);
3.9 +uint32_t *list_first(uint32_t *list, struct array *pool);
3.10 +uint32_t *list_next(uint32_t *list);
3.11 +void list_remap_pool(struct array *pool, uint32_t *map);
3.12 +void list_remap_if_immediate(uint32_t *list, uint32_t *map);
3.13 +#define LIST_VALUE(list) (*(list) & RAZOR_ENTRY_MASK)
3.14 +#define LIST_FLAGS(list) (*(list) & ~RAZOR_ENTRY_MASK)
3.15 +
3.16 struct hashtable {
3.17 struct array buckets;
3.18 struct array *pool;