diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-08-13 01:00:18 +0200 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-09-15 16:08:50 +0200 |
commit | d5099efc47d4e6ac60816b5381a5f607ab03f06e (patch) | |
tree | 661308aae8a0885e90da25874e7df3e795532356 /src/journal/catalog.c | |
parent | f44541bc934c6e2b02155559e9eeb17a13a09558 (diff) |
hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.
systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
Diffstat (limited to 'src/journal/catalog.c')
-rw-r--r-- | src/journal/catalog.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c index f03357dedf..41d450b154 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -64,7 +64,7 @@ typedef struct CatalogItem { le64_t offset; } CatalogItem; -unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { +static unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { const CatalogItem *i = p; uint64_t u; size_t l, sz; @@ -81,7 +81,7 @@ unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_S return (unsigned long) u; } -int catalog_compare_func(const void *a, const void *b) { +static int catalog_compare_func(const void *a, const void *b) { const CatalogItem *i = a, *j = b; unsigned k; @@ -95,6 +95,11 @@ int catalog_compare_func(const void *a, const void *b) { return strcmp(i->language, j->language); } +const struct hash_ops catalog_hash_ops = { + .hash = catalog_hash_func, + .compare = catalog_compare_func +}; + static int finish_item( Hashmap *h, struct strbuf *sb, @@ -407,7 +412,7 @@ int catalog_update(const char* database, const char* root, const char* const* di unsigned n; long r; - h = hashmap_new(catalog_hash_func, catalog_compare_func); + h = hashmap_new(&catalog_hash_ops); sb = strbuf_new(); if (!h || !sb) { |