1.1 --- a/razor.c Fri Feb 08 11:19:36 2008 -0500
1.2 +++ b/razor.c Fri Feb 08 14:39:34 2008 -0500
1.3 @@ -47,21 +47,21 @@
1.4 struct razor_package {
1.5 uint32_t name;
1.6 uint32_t version;
1.7 - uint32_t properties;
1.8 - uint32_t files;
1.9 + struct list_head properties;
1.10 + struct list_head files;
1.11 };
1.12
1.13 struct razor_property {
1.14 uint32_t name;
1.15 uint32_t relation;
1.16 uint32_t version;
1.17 - uint32_t packages;
1.18 + struct list_head packages;
1.19 };
1.20
1.21 struct razor_entry {
1.22 uint32_t name;
1.23 uint32_t start;
1.24 - uint32_t packages;
1.25 + struct list_head packages;
1.26 };
1.27
1.28 struct razor_set {
1.29 @@ -242,9 +242,9 @@
1.30 void
1.31 razor_importer_finish_package(struct razor_importer *importer)
1.32 {
1.33 - list_set (&importer->package->properties,
1.34 - &importer->set->property_pool,
1.35 - &importer->properties);
1.36 + list_set_array(&importer->package->properties,
1.37 + &importer->set->property_pool,
1.38 + &importer->properties);
1.39
1.40 array_release(&importer->properties);
1.41 }
1.42 @@ -263,8 +263,8 @@
1.43 p->name = hashtable_tokenize(&importer->table, name) | (type << 30);
1.44 p->relation = relation;
1.45 p->version = hashtable_tokenize(&importer->table, version);
1.46 - p->packages = importer->package -
1.47 - (struct razor_package *) importer->set->packages.data;
1.48 + list_set_ptr(&p->packages, importer->package -
1.49 + (struct razor_package *) importer->set->packages.data);
1.50
1.51 r = array_add(&importer->properties, sizeof *r);
1.52 *r = p - (struct razor_property *) importer->set->properties.data;
1.53 @@ -474,7 +474,8 @@
1.54 {
1.55 struct razor_property *rp, *up, *rp_end;
1.56 struct array *pkgs, *p;
1.57 - uint32_t *map, *rmap, *r;
1.58 + struct list_head *r;
1.59 + uint32_t *map, *rmap;
1.60 int i, count, unique;
1.61
1.62 count = set->properties.size / sizeof(struct razor_property);
1.63 @@ -507,7 +508,7 @@
1.64 set->properties.size = (void *) up - set->properties.data;
1.65 rp_end = up;
1.66 for (rp = set->properties.data, p = pkgs; rp < rp_end; rp++, p++) {
1.67 - list_set(&rp->packages, &set->package_pool, p);
1.68 + list_set_array(&rp->packages, &set->package_pool, p);
1.69 array_release(p);
1.70 }
1.71
1.72 @@ -557,7 +558,7 @@
1.73 e->start = p->count > 0 ? s : 0;
1.74 s += p->count;
1.75
1.76 - list_set(&e->packages, &set->package_pool, &p->packages);
1.77 + list_set_array(&e->packages, &set->package_pool, &p->packages);
1.78 array_release(&p->packages);
1.79 p++;
1.80 }
1.81 @@ -579,7 +580,7 @@
1.82
1.83 end = properties->data + properties->size;
1.84 for (p = properties->data; p < end; p++)
1.85 - list_remap_if_immediate(&p->packages, rmap);
1.86 + list_remap_head(&p->packages, rmap);
1.87 }
1.88
1.89 static void
1.90 @@ -645,7 +646,7 @@
1.91 e = array_add(&importer->set->files, sizeof *e);
1.92 e->name = root.name | RAZOR_ENTRY_LAST;
1.93 e->start = 1;
1.94 - list_init(&e->packages);
1.95 + list_set_empty(&e->packages);
1.96
1.97 serialize_files(importer->set, &root, &importer->set->files);
1.98
1.99 @@ -658,7 +659,8 @@
1.100 struct razor_package *p, *packages;
1.101 struct array *pkgs;
1.102 struct razor_entry *e, *end;
1.103 - uint32_t *r, *q;
1.104 + struct list *r;
1.105 + uint32_t *q;
1.106 int i, count;
1.107
1.108 count = set->packages.size / sizeof *p;
1.109 @@ -666,10 +668,10 @@
1.110
1.111 end = set->files.data + set->files.size;
1.112 for (e = set->files.data; e < end; e++) {
1.113 - list_remap_if_immediate(&e->packages, rmap);
1.114 + list_remap_head(&e->packages, rmap);
1.115 r = list_first(&e->packages, &set->package_pool);
1.116 while (r) {
1.117 - q = array_add(&pkgs[LIST_VALUE(r)], sizeof *q);
1.118 + q = array_add(&pkgs[r->data], sizeof *q);
1.119 *q = e - (struct razor_entry *) set->files.data;
1.120 r = list_next(r);
1.121 }
1.122 @@ -677,7 +679,7 @@
1.123
1.124 packages = set->packages.data;
1.125 for (i = 0; i < count; i++) {
1.126 - list_set(&packages[i].files, &set->file_pool, &pkgs[i]);
1.127 + list_set_array(&packages[i].files, &set->file_pool, &pkgs[i]);
1.128 array_release(&pkgs[i]);
1.129 }
1.130 free(pkgs);
1.131 @@ -722,12 +724,12 @@
1.132 struct razor_package_iterator {
1.133 struct razor_set *set;
1.134 struct razor_package *package, *end;
1.135 - uint32_t *index;
1.136 + struct list *index;
1.137 };
1.138
1.139 struct razor_package_iterator *
1.140 razor_package_iterator_create_with_index(struct razor_set *set,
1.141 - uint32_t *index)
1.142 + struct list *index)
1.143 {
1.144 struct razor_package_iterator *pi;
1.145
1.146 @@ -755,7 +757,7 @@
1.147 razor_package_iterator_create_for_property(struct razor_set *set,
1.148 struct razor_property *property)
1.149 {
1.150 - uint32_t *index;
1.151 + struct list *index;
1.152
1.153 index = list_first(&property->packages, &set->package_pool);
1.154 return razor_package_iterator_create_with_index(set, index);
1.155 @@ -775,7 +777,7 @@
1.156 valid = p < pi->end;
1.157 } else if (pi->index) {
1.158 packages = pi->set->packages.data;
1.159 - p = &packages[LIST_VALUE(pi->index)];
1.160 + p = &packages[pi->index->data];
1.161 pi->index = list_next(pi->index);
1.162 valid = 1;
1.163 } else
1.164 @@ -819,7 +821,7 @@
1.165 struct razor_property_iterator {
1.166 struct razor_set *set;
1.167 struct razor_property *property, *end;
1.168 - uint32_t *index;
1.169 + struct list *index;
1.170 };
1.171
1.172 struct razor_property_iterator *
1.173 @@ -832,8 +834,8 @@
1.174 pi->set = set;
1.175
1.176 if (package) {
1.177 - pi->index = (uint32_t *)
1.178 - set->property_pool.data + package->properties;
1.179 + pi->index = list_first(&package->properties,
1.180 + &set->property_pool);
1.181 } else {
1.182 pi->property = set->properties.data;
1.183 pi->end = set->properties.data + set->properties.size;
1.184 @@ -859,7 +861,7 @@
1.185 valid = p < pi->end;
1.186 } else if (pi->index) {
1.187 properties = pi->set->properties.data;
1.188 - p = &properties[LIST_VALUE(pi->index)];
1.189 + p = &properties[pi->index->data];
1.190 pi->index = list_next(pi->index);
1.191 valid = 1;
1.192 } else
1.193 @@ -955,7 +957,7 @@
1.194 const char *filename)
1.195 {
1.196 struct razor_entry *entry;
1.197 - uint32_t *index;
1.198 + struct list *index;
1.199
1.200 entry = find_entry(set, set->files.data, filename);
1.201 if (entry == NULL)
1.202 @@ -965,8 +967,8 @@
1.203 return razor_package_iterator_create_with_index(set, index);
1.204 }
1.205
1.206 -static uint32_t *
1.207 -list_package_files(struct razor_set *set, uint32_t *r,
1.208 +static struct list *
1.209 +list_package_files(struct razor_set *set, struct list *r,
1.210 struct razor_entry *dir, uint32_t end,
1.211 char *prefix)
1.212 {
1.213 @@ -980,13 +982,13 @@
1.214
1.215 e = entries + dir->start;
1.216 do {
1.217 - if (entries + LIST_VALUE(r) == e) {
1.218 + if (entries + r->data == e) {
1.219 printf("%s/%s\n", prefix,
1.220 pool + (e->name & RAZOR_ENTRY_MASK));
1.221 r = list_next(r);
1.222 if (!r)
1.223 return NULL;
1.224 - if (LIST_VALUE(r) >= end)
1.225 + if (r->data >= end)
1.226 return r;
1.227 }
1.228 } while (!((e++)->name & RAZOR_ENTRY_LAST));
1.229 @@ -1008,7 +1010,7 @@
1.230 next = f->start;
1.231 }
1.232
1.233 - file = LIST_VALUE(r);
1.234 + file = r->data;
1.235 if (e->start <= file && file < next) {
1.236 len = strlen(prefix);
1.237 prefix[len] = '/';
1.238 @@ -1026,7 +1028,8 @@
1.239 razor_set_list_package_files(struct razor_set *set, const char *name)
1.240 {
1.241 struct razor_package *package;
1.242 - uint32_t *r, end;
1.243 + struct list *r;
1.244 + uint32_t end;
1.245 char buffer[512];
1.246
1.247 package = razor_set_get_package(set, name);
1.248 @@ -1158,7 +1161,7 @@
1.249 uint32_t flags)
1.250 {
1.251 char *pool;
1.252 - uint32_t *r;
1.253 + struct list *r;
1.254 struct razor_package *p;
1.255
1.256 pool = source->set->string_pool.data;
1.257 @@ -1171,7 +1174,7 @@
1.258
1.259 r = list_first(&package->properties, &source->set->property_pool);
1.260 while (r) {
1.261 - source->property_map[LIST_VALUE(r)] = 1;
1.262 + source->property_map[r->data] = 1;
1.263 r = list_next(r);
1.264 }
1.265 }
1.266 @@ -1301,20 +1304,22 @@
1.267 }
1.268
1.269 static void
1.270 -emit_properties(uint32_t *properties, struct array *source_pool,
1.271 +emit_properties(struct list_head *properties, struct array *source_pool,
1.272 uint32_t *map, struct array *pool)
1.273 {
1.274 - uint32_t r, *p, *q;
1.275 + uint32_t r;
1.276 + struct list *p, *q;
1.277
1.278 r = pool->size / sizeof *q;
1.279 p = list_first(properties, source_pool);
1.280 while (p) {
1.281 q = array_add(pool, sizeof *q);
1.282 - *q = map[LIST_VALUE(p)] | LIST_FLAGS(p);
1.283 + q->data = map[p->data];
1.284 + q->flags = p->flags;
1.285 p = list_next(p);
1.286 }
1.287
1.288 - *properties = r;
1.289 + list_set_ptr(properties, r);
1.290 }
1.291
1.292 /* Rebuild property->packages maps. We can't just remap these, as a
1.293 @@ -1328,7 +1333,8 @@
1.294 struct razor_package *pkg, *pkg_end;
1.295 struct razor_property *prop, *prop_end;
1.296 struct array *pool;
1.297 - uint32_t *r, *q;
1.298 + struct list *r;
1.299 + uint32_t *q;
1.300 int count;
1.301
1.302 count = set->properties.size / sizeof (struct razor_property);
1.303 @@ -1339,7 +1345,7 @@
1.304 for (pkg = set->packages.data; pkg < pkg_end; pkg++) {
1.305 r = list_first(&pkg->properties, pool);
1.306 while (r) {
1.307 - q = array_add(&pkgs[LIST_VALUE(r)], sizeof *q);
1.308 + q = array_add(&pkgs[r->data], sizeof *q);
1.309 *q = pkg - (struct razor_package *) set->packages.data;
1.310 r = list_next(r);
1.311 }
1.312 @@ -1348,7 +1354,7 @@
1.313 prop_end = set->properties.data + set->properties.size;
1.314 a = pkgs;
1.315 for (prop = set->properties.data; prop < prop_end; prop++, a++) {
1.316 - list_set(&prop->packages, pool, a);
1.317 + list_set_array(&prop->packages, pool, a);
1.318 array_release(a);
1.319 }
1.320 free(pkgs);
1.321 @@ -1463,7 +1469,7 @@
1.322 } else {
1.323 pkg = array_add(list, sizeof *pkg);
1.324 /* We just pull in the first package that provides */
1.325 - *pkg = LIST_VALUE(list_first(&p->packages, package_pool));
1.326 + *pkg = list_first(&p->packages, package_pool)->data;
1.327 }
1.328 }
1.329 }
2.1 --- a/types.c Fri Feb 08 11:19:36 2008 -0500
2.2 +++ b/types.c Fri Feb 08 14:39:34 2008 -0500
2.3 @@ -43,48 +43,58 @@
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 +/* RAZOR_IMMEDIATE and RAZOR_ENTRY_LAST must have the same value */
2.11 +#define RAZOR_ENTRY_LAST 0x2
2.12 +#define RAZOR_IMMEDIATE 0x2
2.13 +#define RAZOR_EMPTY_LIST 0x3
2.14
2.15 void
2.16 -list_init(uint32_t *list)
2.17 +list_set_empty(struct list_head *head)
2.18 {
2.19 - *list = ~0;
2.20 + head->list_ptr = ~0;
2.21 + head->flags = RAZOR_EMPTY_LIST;
2.22 }
2.23
2.24 void
2.25 -list_set(uint32_t *list, struct array *pool, struct array *items)
2.26 +list_set_ptr(struct list_head *head, uint32_t ptr)
2.27 {
2.28 - uint32_t *p;
2.29 + head->list_ptr = ptr;
2.30 + head->flags = 0;
2.31 +}
2.32 +
2.33 +void
2.34 +list_set_array(struct list_head *head, struct array *pool, struct array *items)
2.35 +{
2.36 + struct list *p;
2.37
2.38 if (items->size == 0) {
2.39 - list_init(list);
2.40 + list_set_empty(head);
2.41 } else if (items->size == sizeof (uint32_t)) {
2.42 - *list = *(uint32_t *) items->data | RAZOR_IMMEDIATE;
2.43 + head->list_ptr = *(uint32_t *) items->data;
2.44 + head->flags = RAZOR_IMMEDIATE;
2.45 } else {
2.46 p = array_add(pool, items->size);
2.47 memcpy(p, items->data, items->size);
2.48 - p[items->size / sizeof *p - 1] |= RAZOR_ENTRY_LAST;
2.49 - *list = p - (uint32_t *) pool->data;
2.50 + p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST;
2.51 + list_set_ptr(head, p - (struct list *) pool->data);
2.52 }
2.53 }
2.54
2.55 -uint32_t *
2.56 -list_first(uint32_t *list, struct array *pool)
2.57 +struct list *
2.58 +list_first(struct list_head *head, struct array *pool)
2.59 {
2.60 - if (*list == ~0)
2.61 + if (head->flags == RAZOR_EMPTY_LIST)
2.62 return NULL;
2.63 - else if (*list & RAZOR_IMMEDIATE)
2.64 - return list;
2.65 + else if (head->flags == RAZOR_IMMEDIATE)
2.66 + return (struct list *) head;
2.67 else
2.68 - return (uint32_t *) pool->data + (*list & RAZOR_ENTRY_MASK);
2.69 + return (struct list *) pool->data + head->list_ptr;
2.70 }
2.71
2.72 -uint32_t *
2.73 -list_next(uint32_t *list)
2.74 +struct list *
2.75 +list_next(struct list *list)
2.76 {
2.77 - if (*list & ~RAZOR_ENTRY_MASK)
2.78 + if (list->flags)
2.79 return NULL;
2.80 return ++list;
2.81 }
2.82 @@ -92,18 +102,18 @@
2.83 void
2.84 list_remap_pool(struct array *pool, uint32_t *map)
2.85 {
2.86 - uint32_t *p, *end;
2.87 + struct list *p, *end;
2.88
2.89 end = pool->data + pool->size;
2.90 for (p = pool->data; p < end; p++)
2.91 - *p = map[LIST_VALUE(p)] | LIST_FLAGS(p);
2.92 + p->data = map[p->data];
2.93 }
2.94
2.95 void
2.96 -list_remap_if_immediate(uint32_t *list, uint32_t *map)
2.97 +list_remap_head(struct list_head *head, uint32_t *map)
2.98 {
2.99 - if ((*list & ~RAZOR_ENTRY_MASK) == RAZOR_IMMEDIATE)
2.100 - *list = map[LIST_VALUE(list)] | LIST_FLAGS(list);
2.101 + if (head->flags == RAZOR_IMMEDIATE)
2.102 + head->list_ptr = map[head->list_ptr];
2.103 }
2.104
2.105
3.1 --- a/types.h Fri Feb 08 11:19:36 2008 -0500
3.2 +++ b/types.h Fri Feb 08 14:39:34 2008 -0500
3.3 @@ -13,14 +13,26 @@
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 +struct list_head {
3.12 + uint list_ptr : 30;
3.13 + uint flags : 2;
3.14 +};
3.15 +
3.16 +struct list {
3.17 + uint data : 30;
3.18 + uint flags : 2;
3.19 +};
3.20 +
3.21 +void list_set_empty(struct list_head *head);
3.22 +void list_set_ptr(struct list_head *head, uint32_t ptr);
3.23 +void list_set_array(struct list_head *head, struct array *pool, struct array *items);
3.24 +
3.25 +struct list *list_first(struct list_head *head, struct array *pool);
3.26 +struct list *list_next(struct list *list);
3.27 +
3.28 void list_remap_pool(struct array *pool, uint32_t *map);
3.29 -void list_remap_if_immediate(uint32_t *list, uint32_t *map);
3.30 -#define LIST_VALUE(list) (*(list) & RAZOR_ENTRY_MASK)
3.31 -#define LIST_FLAGS(list) (*(list) & ~RAZOR_ENTRY_MASK)
3.32 +void list_remap_head(struct list_head *list, uint32_t *map);
3.33 +
3.34
3.35 struct hashtable {
3.36 struct array buckets;