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

Function cr_str

internal/cbm/result_compact.c:128–168  ·  view source on GitHub ↗

A string field: interned by content. COPY rewrites the field. */

Source from the content-addressed store, hash-verified

126
127/* A string field: interned by content. COPY rewrites the field. */
128static void cr_str(cr_ctx_t *c, const char **field) {
129 const char *s = *field;
130 if (!s) {
131 return;
132 }
133 if (c->phase == CR_RELOCATE) {
134 if (cr_in_old_block(c, s)) {
135 *field = s + c->delta;
136 }
137 return;
138 }
139 if (c->phase == CR_COUNT) {
140 c->refs++;
141 return;
142 }
143 cr_slot_t *slot;
144 if (c->phase == CR_COPY && c->seq && c->seq_pos < c->seq_len) {
145 slot = &c->slots[c->seq[c->seq_pos++]];
146 } else {
147 slot = cr_slot(c, s);
148 }
149 if (c->phase == CR_MEASURE) {
150 if (c->seq && c->seq_len < c->refs) {
151 c->seq[c->seq_len++] = (uint32_t)(slot - c->slots);
152 }
153 if (!slot->dst) {
154 slot->dst = (char *)s; /* mark as booked; reset before COPY */
155 c->bytes += cr_aligned(slot->len + SKIP_ONE);
156 }
157 return;
158 }
159 if (!slot->dst) {
160 char *copy = (char *)cr_alloc(c, slot->len + SKIP_ONE);
161 if (!copy) {
162 return;
163 }
164 memcpy(copy, slot->src, slot->len + SKIP_ONE);
165 slot->dst = copy;
166 }
167 *field = slot->dst;
168}
169
170/* A blob (fingerprint, retained source): copied verbatim. */
171static void cr_blob(cr_ctx_t *c, const void **field, size_t bytes) {

Callers 6

cr_listFunction · 0.85
cr_counted_listFunction · 0.85
cr_walk_defFunction · 0.85
cr_walk_callFunction · 0.85
cr_py_stringFunction · 0.85
cr_walkFunction · 0.85

Calls 4

cr_in_old_blockFunction · 0.85
cr_slotFunction · 0.85
cr_alignedFunction · 0.85
cr_allocFunction · 0.85

Tested by

no test coverage detected