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

Function cbm_doclink_note_doc_line

internal/cbm/doclink.c:302–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t line) {
303 if (!ctx || !doc || !cbm_doclink_lang_supported(ctx->language)) {
304 return;
305 }
306 CBMArena *a = doclink_scratch(ctx);
307 doc_line_map_t *m = (doc_line_map_t *)ctx->doc_lines;
308 if (!m) {
309 m = (doc_line_map_t *)cbm_arena_alloc(a, sizeof(*m));
310 if (!m) {
311 doc_line_lost(ctx);
312 return;
313 }
314 memset(m, 0, sizeof(*m));
315 ctx->doc_lines = m;
316 }
317 if (m->count >= m->cap) {
318 int ncap = m->cap ? m->cap * PAIR_LEN : DOC_LINE_MAP_INIT;
319 doc_line_ent_t *grown;
320#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
321 if (cbm_doclink_test_fail_alloc(CBM_DOCLINK_ALLOC_DOC_LINE)) {
322 grown = NULL;
323 } else
324#endif
325 {
326 grown = (doc_line_ent_t *)cbm_arena_alloc(a, (size_t)ncap * sizeof(*grown));
327 }
328 if (!grown) {
329 doc_line_lost(ctx);
330 return;
331 }
332 if (m->count > 0) {
333 memcpy(grown, m->items, (size_t)m->count * sizeof(*grown));
334 }
335 m->items = grown;
336 m->cap = ncap;
337 }
338 m->items[m->count++] = (doc_line_ent_t){.doc = doc, .line = line};
339 m->sorted = false;
340}
341
342static int doc_line_cmp(const void *a, const void *b) {
343 uintptr_t x = (uintptr_t)((const doc_line_ent_t *)a)->doc;

Callers 2

doc_run_textFunction · 0.85
doc_perl_moduleFunction · 0.85

Calls 5

doclink_scratchFunction · 0.85
doc_line_lostFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected