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. */
| 128 | * heap_strdup). The returned pointer is stable for the buffer's lifetime and |
| 129 | * must never be freed or mutated by callers. Returns NULL only on OOM. */ |
| 130 | static const char *gb_intern(cbm_gbuf_t *gb, const char *s) { |
| 131 | const char *key = s ? s : "{}"; |
| 132 | const char *found = cbm_ht_get(gb->intern_pool, key); |
| 133 | if (found) { |
| 134 | return found; |
| 135 | } |
| 136 | char *copy = strdup(key); |
| 137 | if (copy) { |
| 138 | cbm_ht_set(gb->intern_pool, copy, copy); /* key == value == owned copy */ |
| 139 | } |
| 140 | return copy; |
| 141 | } |
| 142 | |
| 143 | static void make_id_key(char *buf, size_t bufsz, int64_t id) { |
| 144 | snprintf(buf, bufsz, "%lld", (long long)id); |
no test coverage detected