diff options
Diffstat (limited to 'WWW/Library/Implementation/HTAtom.c')
-rw-r--r-- | WWW/Library/Implementation/HTAtom.c | 79 |
1 files changed, 6 insertions, 73 deletions
diff --git a/WWW/Library/Implementation/HTAtom.c b/WWW/Library/Implementation/HTAtom.c index 914a7f37..07eca771 100644 --- a/WWW/Library/Implementation/HTAtom.c +++ b/WWW/Library/Implementation/HTAtom.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTAtom.c,v 1.20 2016/11/24 15:29:50 tom Exp $ + * $LynxId: HTAtom.c,v 1.22 2018/03/06 09:46:58 tom Exp $ * * Atoms: Names to numbers HTAtom.c * ======================= @@ -17,15 +17,13 @@ */ #include <HTUtils.h> - -#define HASH_SIZE 101 /* Tunable */ #include <HTAtom.h> - #include <HTList.h> - #include <LYexit.h> #include <LYLeaks.h> +#define HASH_SIZE 101 /* Arbitrary prime. Memory/speed tradeoff */ + static HTAtom *hash_table[HASH_SIZE]; static BOOL initialised = NO; @@ -36,9 +34,6 @@ static BOOL initialised = NO; static void free_atoms(void); #endif -/* - * Alternate hashing function. - */ #define HASH_FUNCTION(cp_hash) ((strlen(cp_hash) * UCH(*cp_hash)) % HASH_SIZE) HTAtom *HTAtom_for(const char *string) @@ -46,38 +41,22 @@ HTAtom *HTAtom_for(const char *string) size_t hash; HTAtom *a; - /* First time around, clear hash table - */ - /* - * Memory leak fixed. - * 05-29-94 Lynx 2-3-1 Garrett Arch Blythe - */ if (!initialised) { - int i; - - for (i = 0; i < HASH_SIZE; i++) - hash_table[i] = (HTAtom *) 0; + memset(hash_table, 0, sizeof(hash_table)); initialised = YES; #ifdef LY_FIND_LEAKS atexit(free_atoms); #endif } - /* Generate hash function - */ hash = HASH_FUNCTION(string); - /* Search for the string in the list - */ for (a = hash_table[hash]; a; a = a->next) { if (0 == strcasecomp(a->name, string)) { - /* CTRACE((tfp, "HTAtom: Old atom %p for `%s'\n", a, string)); */ - return a; /* Found: return it */ + return a; } } - /* Generate a new entry - */ a = (HTAtom *) malloc(sizeof(*a)); if (a == NULL) outofmem(__FILE__, "HTAtom_for"); @@ -87,11 +66,8 @@ HTAtom *HTAtom_for(const char *string) outofmem(__FILE__, "HTAtom_for"); strcpy(a->name, string); - a->next = hash_table[hash]; /* Put onto the head of list */ + a->next = hash_table[hash]; hash_table[hash] = a; -#ifdef NOT_DEFINED - CTRACE((tfp, "HTAtom: New atom %p for `%s'\n", a, string)); -#endif /* NOT_DEFINED */ return a; } @@ -129,46 +105,3 @@ static void free_atoms(void) } } #endif /* LY_FIND_LEAKS */ - -static BOOL mime_match(const char *name, - const char *templ) -{ - if (name && templ) { - static char *n1 = NULL; - static char *t1 = NULL; - char *n2; - char *t2; - - StrAllocCopy(n1, name); /* These also free the ones */ - StrAllocCopy(t1, templ); /* from previous call. */ - - if (!(n2 = StrChr(n1, '/')) || !(t2 = StrChr(t1, '/'))) - return NO; - - *(n2++) = (char) 0; - *(t2++) = (char) 0; - - if ((0 == strcmp(t1, "*") || 0 == strcmp(t1, n1)) && - (0 == strcmp(t2, "*") || 0 == strcmp(t2, n2))) - return YES; - } - return NO; -} - -HTList *HTAtom_templateMatches(const char *templ) -{ - HTList *matches = HTList_new(); - - if (initialised && templ) { - int i; - HTAtom *cur; - - for (i = 0; i < HASH_SIZE; i++) { - for (cur = hash_table[i]; cur; cur = cur->next) { - if (mime_match(cur->name, templ)) - HTList_addObject(matches, (void *) cur); - } - } - } - return matches; -} |