The constants of package directory `dir` (its non-test Go files). */
| 1382 | |
| 1383 | /* The constants of package directory `dir` (its non-test Go files). */ |
| 1384 | static CBMHashTable *gc_consts(gc_t *g, const char *dir) { |
| 1385 | CBMHashTable *t = cbm_ht_get(g->consts, dir); |
| 1386 | if (t) { |
| 1387 | return t; |
| 1388 | } |
| 1389 | t = cbm_ht_create(0); |
| 1390 | char *key = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, dir); |
| 1391 | if (!t || !key) { |
| 1392 | if (t) { |
| 1393 | cbm_ht_free(t); |
| 1394 | } |
| 1395 | cbm_free(CBM_MEM_CLASS_OTHER, key); |
| 1396 | return NULL; |
| 1397 | } |
| 1398 | cbm_ht_set(g->consts, key, t); |
| 1399 | size_t dl = strlen(dir); |
| 1400 | for (int i = 0; i < g->nfiles; i++) { |
| 1401 | const char *fp = g->files[i]->file_path; |
| 1402 | const char *slash = strrchr(fp, '/'); |
| 1403 | size_t fdl = slash ? (size_t)(slash - fp) : 0; |
| 1404 | size_t fl = strlen(fp); |
| 1405 | if (fdl != dl || strncmp(fp, dir, dl) != 0 || !op_is_go(fp) || |
| 1406 | (fl > OP_SLEN("_test.go") && strcmp(fp + fl - OP_SLEN("_test.go"), "_test.go") == 0)) { |
| 1407 | continue; |
| 1408 | } |
| 1409 | char path[CBM_SZ_4K]; |
| 1410 | snprintf(path, sizeof(path), "%s/%s", g->ctx->repo_path, fp); |
| 1411 | char *text = op_read_file(path); |
| 1412 | if (text) { |
| 1413 | gc_scan_consts(t, text); |
| 1414 | cbm_free(CBM_MEM_CLASS_OTHER, text); |
| 1415 | } |
| 1416 | } |
| 1417 | return t; |
| 1418 | } |
| 1419 | |
| 1420 | /* ── Values ── */ |
| 1421 |
no test coverage detected