X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=fc9f8684256548e89cde59b87623f6ee75a781db;hb=10b60d36fcf6cc9532bf397866c5bdc3393246eb;hp=64934a6c2bc35b3afb9b592536b859bc0dde73c5;hpb=f5626be739a1e1b61f89d7a389be3c4b5d4d9128;p=swftools.git diff --git a/lib/q.c b/lib/q.c index 64934a6..fc9f868 100644 --- a/lib/q.c +++ b/lib/q.c @@ -524,13 +524,14 @@ void trie_rollback(trie_t*t) // ------------------------------- crc32 -------------------------------------- -static unsigned int*crc32 = 0; +static unsigned int crc32[256]; +static char crc32_initialized=0; static void crc32_init(void) { int t; - if(crc32) + if(crc32_initialized) return; - crc32= (unsigned int*)rfx_alloc(sizeof(unsigned int)*256); + crc32_initialized = 1; for(t=0; t<256; t++) { unsigned int c = t; int s; @@ -643,14 +644,12 @@ char* string_escape(string_t*str) unsigned int crc32_add_byte(unsigned int checksum, unsigned char b) { - if(!crc32) - crc32_init(); + crc32_init(); return checksum>>8 ^ crc32[(b^checksum)&0xff]; } unsigned int crc32_add_string(unsigned int checksum, const char*s) { - if(!crc32) - crc32_init(); + crc32_init(); if(!s) return checksum; while(*s) { @@ -664,8 +663,7 @@ unsigned int string_hash(const string_t*str) { int t; unsigned int checksum = 0; - if(!crc32) - crc32_init(); + crc32_init(); for(t=0;tlen;t++) { checksum = checksum>>8 ^ crc32[(str->str[t]^checksum)&0xff]; } @@ -675,8 +673,7 @@ unsigned int string_hash2(const char*str) { unsigned int checksum = 0; const char*p = str; - if(!crc32) - crc32_init(); + crc32_init(); while(*p) { checksum = checksum>>8 ^ crc32[(*p^checksum)&0xff]; p++; @@ -1162,6 +1159,34 @@ char dict_del(dict_t*h, const void*key) return 0; } +char dict_del2(dict_t*h, const void*key, void*data) +{ + if(!h->num) + return 0; + unsigned int hash = h->key_type->hash(key) % h->hashsize; + dictentry_t*head = h->slots[hash]; + dictentry_t*e = head, *prev=0; + while(e) { + if(h->key_type->equals(e->key, key) && e->data == data) { + dictentry_t*next = e->next; + h->key_type->free(e->key); + memset(e, 0, sizeof(dictentry_t)); + rfx_free(e); + if(e == head) { + h->slots[hash] = next; + } else { + assert(prev); + prev->next = next; + } + h->num--; + return 1; + } + prev = e; + e = e->next; + } + return 0; +} + dictentry_t* dict_get_slot(dict_t*h, const void*key) { if(!h->num)