| 329 | } |
| 330 | |
| 331 | const void *memintern(const void *data, size_t len) |
| 332 | { |
| 333 | static struct hashmap map; |
| 334 | struct pool_entry key, *e; |
| 335 | |
| 336 | /* initialize string pool hashmap */ |
| 337 | if (!map.tablesize) |
| 338 | hashmap_init(&map, pool_entry_cmp, NULL, 0); |
| 339 | |
| 340 | /* lookup interned string in pool */ |
| 341 | hashmap_entry_init(&key.ent, memhash(data, len)); |
| 342 | key.len = len; |
| 343 | e = hashmap_get_entry(&map, &key, ent, data); |
| 344 | if (!e) { |
| 345 | /* not found: create it */ |
| 346 | FLEX_ALLOC_MEM(e, data, data, len); |
| 347 | hashmap_entry_init(&e->ent, key.ent.hash); |
| 348 | e->len = len; |
| 349 | hashmap_add(&map, &e->ent); |
| 350 | } |
| 351 | return e->data; |
| 352 | } |
no test coverage detected