=== modified file 'driver-ti.c' --- driver-ti.c 2008-11-12 23:58:20 +0000 +++ driver-ti.c 2008-11-12 16:32:17 +0000 @@ -10,9 +10,7 @@ #include /* To be efficient at lookups, we store the byte sequence => keyinfo mapping - * in a trie. This avoids a slow linear search through a flat list of - * sequences. Because it is likely most nodes will be very sparse, we optimise - * vector to store an extent map after the database is loaded. + * in a trie. This avoids a slow linear search though a flat list of sequences */ typedef enum { @@ -31,8 +29,7 @@ struct trie_node_arr { trie_nodetype type; - unsigned char min, max; /* INCLUSIVE endpoints of the extent range */ - struct trie_node *arr[0]; + struct trie_node *arr[256]; }; typedef struct { @@ -60,18 +57,17 @@ return (struct trie_node*)n; } -static struct trie_node *new_node_arr(unsigned char min, unsigned char max) +static struct trie_node *new_node_arr(void) { - struct trie_node_arr *n = malloc(sizeof(struct trie_node_arr) + ((int)max-min+1) * sizeof(void*)); + struct trie_node_arr *n = malloc(sizeof(struct trie_node_arr)); if(!n) return NULL; n->type = TYPE_ARR; - n->min = min; n->max = max; - int i; - for(i = min; i <= max; i++) - n->arr[i-min] = NULL; + unsigned char b; + for(b = 0; b < 255; b++) + n->arr[b] = NULL; return (struct trie_node*)n; } @@ -85,9 +81,7 @@ case TYPE_ARR: { struct trie_node_arr *nar = (struct trie_node_arr*)n; - if(b < nar->min || b > nar->max) - return NULL; - return nar->arr[b - nar->min]; + return nar->arr[b]; } } @@ -102,10 +96,10 @@ case TYPE_ARR: { struct trie_node_arr *nar = (struct trie_node_arr*)n; - int i; - for(i = nar->min; i <= nar->max; i++) - if(nar->arr[i - nar->min]) - free_trie(nar->arr[i - nar->min]); + unsigned char b; + for(b = 0; b < 255; b++) + if(nar->arr[b]) + free_trie(nar->arr[b]); break; } } @@ -113,37 +107,6 @@ free(n); } -static struct trie_node *compress_trie(struct trie_node *n) -{ - if(!n) - return NULL; - - switch(n->type) { - case TYPE_KEY: - return n; - case TYPE_ARR: - { - struct trie_node_arr *nar = (struct trie_node_arr*)n; - unsigned char min, max; - // Find the real bounds - for(min = 0; !nar->arr[min]; min++) - ; - for(max = 0xff; !nar->arr[max]; max--) - ; - - struct trie_node_arr *new = (struct trie_node_arr*)new_node_arr(min, max); - int i; - for(i = min; i <= max; i++) - new->arr[i - min] = compress_trie(nar->arr[i]); - - free(nar); - return (struct trie_node*)new; - } - } - - return n; -} - static void *new_driver(termkey_t *tk, const char *term) { int err; @@ -157,7 +120,7 @@ ti->tk = tk; - ti->root = new_node_arr(0, 0xff); + ti->root = new_node_arr(); if(!ti->root) goto abort_free_ti; @@ -185,8 +148,6 @@ goto abort_free_trie; } - ti->root = compress_trie(ti->root); - return ti; abort_free_trie: @@ -380,7 +341,7 @@ struct trie_node *next; if(seq[pos+1]) // Intermediate node - next = new_node_arr(0, 0xff); + next = new_node_arr(); else // Final key node next = new_node_key(type, sym, modmask, modset); @@ -392,12 +353,7 @@ case TYPE_ARR: { struct trie_node_arr *nar = (struct trie_node_arr*)p; - if(b < nar->min || b > nar->max) { - fprintf(stderr, "ASSERT FAIL: Trie insert at 0x%02x is outside of extent bounds (0x%02x..0x%02x)\n", - b, nar->min, nar->max); - abort(); - } - nar->arr[b - nar->min] = next; + nar->arr[b] = next; p = next; break; }