Intern a repetitive string into the buffer's pool: identical content collapses * to a single heap copy owned by the pool. NULL maps to "{}" (matches * heap_strdup). The returned pointer is stable for the buffer's lifetime and * must never be freed or mutated by callers. Returns NULL only on OOM. */
| 155 | * heap_strdup). The returned pointer is stable for the buffer's lifetime and |
| 156 | * must never be freed or mutated by callers. Returns NULL only on OOM. */ |
| 157 | static const char *gb_intern(cbm_gbuf_t *gb, const char *s) { |
| 158 | const char *key = s ? s : "{}"; |
| 159 | const char *found = cbm_ht_get(gb->intern_pool, key); |
| 160 | if (found) { |
| 161 | return found; |
| 162 | } |
| 163 | char *copy = cbm_mem_strdup(CBM_MEM_CLASS_GBUF_STRING, key); |
| 164 | if (copy) { |
| 165 | cbm_ht_set(gb->intern_pool, copy, copy); /* key == value == owned copy */ |
| 166 | } |
| 167 | return copy; |
| 168 | } |
| 169 | |
| 170 | static void make_id_key(char *buf, size_t bufsz, int64_t id) { |
| 171 | snprintf(buf, bufsz, "%lld", (long long)id); |
no test coverage detected