diff --git a/src/bfu/style.c b/src/bfu/style.c index f2c566c0..f1a38892 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -41,7 +41,7 @@ get_bfu_color(struct terminal *term, unsigned char *stylename) if (!bfu_colors) { /* Initialize the style hash. */ - bfu_colors = init_hash(8, &strhash); + bfu_colors = init_hash8(); if (!bfu_colors) return NULL; last_color_mode = color_mode; diff --git a/src/bookmarks/bookmarks.c b/src/bookmarks/bookmarks.c index fe6c8226..a0f47d70 100644 --- a/src/bookmarks/bookmarks.c +++ b/src/bookmarks/bookmarks.c @@ -339,7 +339,7 @@ add_bookmark_item_to_bookmarks(struct bookmark *bm, struct bookmark *root, int p /* Hash creation if needed. */ if (!bookmark_cache) - bookmark_cache = init_hash(8, &strhash); + bookmark_cache = init_hash8(); /* Create a new entry. */ if (check_bookmark_cache(bm->url)) diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index 3bd7453f..d8c263d2 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -1750,7 +1750,7 @@ format_html_part(struct html_context *html_context, /* Hash creation if needed. */ if (!table_cache) { - table_cache = init_hash(8, &strhash); + table_cache = init_hash8(); } else if (!document) { /* Search for cached entry. */ struct table_cache_entry_key key; diff --git a/src/globhist/globhist.c b/src/globhist/globhist.c index b4801f33..605a7ecf 100644 --- a/src/globhist/globhist.c +++ b/src/globhist/globhist.c @@ -248,7 +248,7 @@ add_item_to_global_history(struct global_history_item *history_item, /* Hash creation if needed. */ if (!globhist_cache) - globhist_cache = init_hash(8, &strhash); + globhist_cache = init_hash8(); if (globhist_cache && globhist_cache_entries < max_globhist_items) { int urllen = strlen(history_item->url); diff --git a/src/main/event.c b/src/main/event.c index 27f63bfa..ff8ab7e8 100644 --- a/src/main/event.c +++ b/src/main/event.c @@ -308,7 +308,7 @@ unregister_event_hooks(struct event_hook_info *hooks) void init_event(void) { - event_hash = init_hash(8, strhash); + event_hash = init_hash8(); } void diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c index 207b44bc..00936148 100644 --- a/src/mime/backend/mailcap.c +++ b/src/mime/backend/mailcap.c @@ -396,7 +396,7 @@ init_mailcap_map(void) unsigned char *path; unsigned int priority = 0; - mailcap_map = init_hash(8, &strhash); + mailcap_map = init_hash8(); if (!mailcap_map) return NULL; /* Try to setup mailcap_path */ diff --git a/src/mime/backend/mimetypes.c b/src/mime/backend/mimetypes.c index f358ad36..c7c73c27 100644 --- a/src/mime/backend/mimetypes.c +++ b/src/mime/backend/mimetypes.c @@ -171,7 +171,7 @@ init_mimetypes_map(void) { unsigned char *path; - mimetypes_map = init_hash(8, &strhash); + mimetypes_map = init_hash8(); if (!mimetypes_map) return NULL; diff --git a/src/protocol/uri.c b/src/protocol/uri.c index c42723e2..ca1a9eb8 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -1518,7 +1518,7 @@ get_uri(unsigned char *string, enum uri_component components) } if (!is_object_used(&uri_cache)) { - uri_cache.map = init_hash(hash_size(3), strhash); + uri_cache.map = init_hash8(); if (!uri_cache.map) return NULL; object_nolock(&uri_cache, "uri_cache"); } diff --git a/src/util/hash.c b/src/util/hash.c index 915191d5..42811e2d 100644 --- a/src/util/hash.c +++ b/src/util/hash.c @@ -22,8 +22,11 @@ * array (same hash value). */ #define hash_mask(n) (hash_size(n) - 1) +#define hash_size(n) (1 << (n)) -struct hash * +static hash_value_T strhash(unsigned char *k, unsigned int length, hash_value_T initval); + +static inline struct hash * init_hash(unsigned int width, hash_func_T func) { struct hash *hash; @@ -47,6 +50,12 @@ init_hash(unsigned int width, hash_func_T func) return hash; } +struct hash * +init_hash8(void) +{ + return init_hash(8, &strhash); +} + void free_hash(struct hash *hash) { @@ -130,7 +139,7 @@ del_hash_item(struct hash *hash, struct hash_item *item) #ifdef X31_HASH /* Fast string hashing. */ -hash_value_T +static hash_value_T strhash(unsigned char *k, /* the key */ unsigned int length, /* the length of the key */ hash_value_T initval /* the previous hash, or an arbitrary value */) @@ -251,7 +260,7 @@ strhash(unsigned char *k, /* the key */ + ((hash_value_T) (k[(a)+2])<<16) \ + ((hash_value_T) (k[(a)+3])<<24)) -hash_value_T +static hash_value_T strhash(unsigned char *k, /* the key */ unsigned int length, /* the length of the key */ hash_value_T initval /* the previous hash, or an arbitrary value */) diff --git a/src/util/hash.h b/src/util/hash.h index b98d0d57..93db7326 100644 --- a/src/util/hash.h +++ b/src/util/hash.h @@ -23,18 +23,16 @@ struct hash { struct list_head hash[1]; /* Must be at end ! */ }; -#define hash_size(n) (1 << (n)) +struct hash *init_hash8(void); -struct hash *init_hash(unsigned int width, hash_func_T func); void free_hash(struct hash *hash); struct hash_item *add_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen, void *value); struct hash_item *get_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen); void del_hash_item(struct hash *hash, struct hash_item *item); -hash_value_T strhash(unsigned char *k, unsigned int length, hash_value_T initval); #define foreach_hash_item(item, hash_table, iterator) \ - for (iterator = 0; iterator < hash_size((hash_table).width); iterator++) \ + for (iterator = 0; iterator < (1 << (hash_table).width); iterator++) \ foreach (item, (hash_table).hash[iterator]) #endif