MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ti_note_occurrence

Function ti_note_occurrence

src/mcp/test_impact_source.c:904–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902/* ── Occurrences ───────────────────────────────────────────────────── */
903
904static bool ti_note_occurrence(cbm_ti_source_t *s, const char *word, size_t len, int file,
905 int line) {
906 char key[256];
907 const char *lookup;
908 char *heap_key = NULL;
909 if (len < sizeof(key)) {
910 memcpy(key, word, len);
911 key[len] = '\0';
912 lookup = key;
913 } else {
914 heap_key = cbm_arena_strndup(&s->arena, word, len);
915 if (!heap_key) {
916 return false;
917 }
918 lookup = heap_key;
919 }
920 ti_places_t *places = cbm_ht_get(s->occurrences, lookup);
921 if (!places) {
922 places = cbm_alloc(CBM_MEM_CLASS_EXTRACT, sizeof(*places));
923 const char *owned = heap_key ? heap_key : cbm_arena_strndup(&s->arena, word, len);
924 if (!places || !owned) {
925 cbm_free(CBM_MEM_CLASS_EXTRACT, places);
926 return false;
927 }
928 *places = (ti_places_t){0};
929 cbm_ht_set(s->occurrences, owned, places);
930 }
931 if (places->count && places->items[places->count - 1].file == file &&
932 places->items[places->count - 1].line == line) {
933 return true; /* one place per line */
934 }
935 if (!ti_grow((void **)&places->items, &places->cap, places->count, sizeof(*places->items))) {
936 return false;
937 }
938 places->items[places->count++] = (cbm_ti_place_t){file, line};
939 return true;
940}
941
942/* `for t in set(TOKEN_RX.findall(ln))` on lines not starting `//` or `*`. */
943static bool ti_scan_line(cbm_ti_source_t *s, int file, int line) {

Callers 1

ti_scan_lineFunction · 0.85

Calls 6

cbm_ht_getFunction · 0.85
cbm_allocFunction · 0.85
cbm_freeFunction · 0.85
cbm_ht_setFunction · 0.85
ti_growFunction · 0.85
cbm_arena_strndupFunction · 0.50

Tested by

no test coverage detected