| 78 | } |
| 79 | |
| 80 | static struct strmap_entry *create_entry(struct strmap *map, |
| 81 | const char *str, |
| 82 | void *data) |
| 83 | { |
| 84 | struct strmap_entry *entry; |
| 85 | |
| 86 | if (map->strdup_strings) { |
| 87 | if (!map->pool) { |
| 88 | FLEXPTR_ALLOC_STR(entry, key, str); |
| 89 | } else { |
| 90 | size_t len = st_add(strlen(str), 1); /* include NUL */ |
| 91 | entry = mem_pool_alloc(map->pool, |
| 92 | st_add(sizeof(*entry), len)); |
| 93 | memcpy(entry + 1, str, len); |
| 94 | entry->key = (void *)(entry + 1); |
| 95 | } |
| 96 | } else if (!map->pool) { |
| 97 | entry = xmalloc(sizeof(*entry)); |
| 98 | } else { |
| 99 | entry = mem_pool_alloc(map->pool, sizeof(*entry)); |
| 100 | } |
| 101 | hashmap_entry_init(&entry->ent, strhash(str)); |
| 102 | if (!map->strdup_strings) |
| 103 | entry->key = str; |
| 104 | entry->value = data; |
| 105 | return entry; |
| 106 | } |
| 107 | |
| 108 | void *strmap_put(struct strmap *map, const char *str, void *data) |
| 109 | { |
no test coverage detected