| 88 | } aa_children_t; |
| 89 | |
| 90 | static aa_tree_child_t *aa_child(aa_children_t *set, const char *name, bool is_file) { |
| 91 | /* Files and folders can share a name; disambiguate the map key. */ |
| 92 | char key[CBM_SZ_512]; |
| 93 | snprintf(key, sizeof(key), "%c%s", is_file ? 'f' : 'd', name); |
| 94 | void *slot = cbm_ht_get(set->by_name, key); |
| 95 | if (slot) |
| 96 | return &set->items[(int)(intptr_t)slot - 1]; |
| 97 | if (set->count >= AA_TREE_MAX_CHILDREN) { |
| 98 | set->dropped++; |
| 99 | return NULL; |
| 100 | } |
| 101 | if (set->count >= set->cap) { |
| 102 | int nc = set->cap ? set->cap * 2 : 64; |
| 103 | aa_tree_child_t *grown = |
| 104 | cbm_realloc(CBM_MEM_CLASS_OTHER, set->items, (size_t)nc * sizeof(aa_tree_child_t)); |
| 105 | if (!grown) |
| 106 | return NULL; |
| 107 | /* The by_name table stores indices, so growth is safe. */ |
| 108 | set->items = grown; |
| 109 | set->cap = nc; |
| 110 | } |
| 111 | aa_tree_child_t *child = &set->items[set->count]; |
| 112 | memset(child, 0, sizeof(*child)); |
| 113 | child->name = aa_strdup(name); |
| 114 | child->region = -1; |
| 115 | child->is_file = is_file; |
| 116 | if (!child->name) |
| 117 | return NULL; |
| 118 | set->count++; |
| 119 | char *owned_key = aa_strdup(key); |
| 120 | if (owned_key) |
| 121 | cbm_ht_set(set->by_name, owned_key, (void *)(intptr_t)set->count); |
| 122 | return child; |
| 123 | } |
| 124 | |
| 125 | static void aa_collect_keys(const char *key, void *value, void *userdata) { |
| 126 | (void)value; |
no test coverage detected