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

Function cs_add_text_items

internal/cbm/doclink_cs.c:2472–2499  ·  view source on GitHub ↗

Add the declarations only the token stream shows and put all items in * document order. */

Source from the content-addressed store, hash-verified

2470/* Add the declarations only the token stream shows and put all items in
2471 * document order. */
2472static void cs_add_text_items(cs_scan_t *s) {
2473 if (s->failed || s->nheads == 0) {
2474 return;
2475 }
2476 int tree_items = s->nitems;
2477 uint32_t *parsed =
2478 (uint32_t *)cs_tmp_alloc(s, (size_t)(tree_items + SKIP_ONE) * sizeof(uint32_t));
2479 if (!parsed) {
2480 return;
2481 }
2482 int nparsed = 0;
2483 for (int i = 0; i < tree_items; i++) {
2484 const cs_item_t *it = &s->items[i];
2485 if (it->tag == 'N' || it->tag == 'F') {
2486 parsed[nparsed++] = cs_namespace_name_start(s, it->node);
2487 } else if (it->tag == 'T' && !ts_node_is_null(it->name)) {
2488 parsed[nparsed++] = ts_node_start_byte(it->name);
2489 }
2490 }
2491 qsort(parsed, (size_t)nparsed, sizeof(uint32_t), cs_u32_cmp);
2492 for (int h = 0; h < s->nheads && !s->failed; h++) {
2493 uint32_t stop = h + SKIP_ONE < s->nheads ? s->heads[h + SKIP_ONE].end : s->root_end_byte;
2494 cs_text_item(s, &s->heads[h], stop, parsed, nparsed);
2495 }
2496 if (s->nitems > tree_items) {
2497 qsort(s->items, (size_t)s->nitems, sizeof(cs_item_t), cs_item_start_cmp);
2498 }
2499}
2500
2501/* ── Emission ────────────────────────────────────────────────────── */
2502

Callers 1

Calls 3

cs_tmp_allocFunction · 0.85
cs_namespace_name_startFunction · 0.85
cs_text_itemFunction · 0.85

Tested by

no test coverage detected