| 238 | } |
| 239 | |
| 240 | static int gm_intern(cbm_graph_mem_t *g, const unsigned char *text, size_t len, int *last) { |
| 241 | if (*last >= 0 && g->type_len[*last] == len && memcmp(g->types[*last], text, len) == 0) { |
| 242 | return *last; |
| 243 | } |
| 244 | for (int i = 0; i < g->type_count; i++) { |
| 245 | if (g->type_len[i] == len && memcmp(g->types[i], text, len) == 0) { |
| 246 | *last = i; |
| 247 | return i; |
| 248 | } |
| 249 | } |
| 250 | if (g->type_count >= GM_MAX_TYPES) { |
| 251 | return -1; |
| 252 | } |
| 253 | char *copy = gm_alloc(len + 1); |
| 254 | if (!copy) { |
| 255 | return -1; |
| 256 | } |
| 257 | memcpy(copy, text, len); |
| 258 | copy[len] = '\0'; |
| 259 | g->types[g->type_count] = copy; |
| 260 | g->type_len[g->type_count] = len; |
| 261 | *last = g->type_count; |
| 262 | return g->type_count++; |
| 263 | } |
| 264 | |
| 265 | static bool gm_grow_u32(uint32_t **arr, size_t *cap, size_t need) { |
| 266 | if (need <= *cap) { |
no test coverage detected