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

Function sb_reserve

internal/cbm/doclink_cs.c:79–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77enum { CS_SB_INIT = 1024, CS_UINT_DIGITS = 16, CS_NAME_MAX = 512 };
78
79static void sb_reserve(cs_sb_t *sb, size_t extra) {
80 if (sb->failed || sb->len + extra + SKIP_ONE <= sb->cap) {
81 return;
82 }
83 size_t ncap = sb->cap ? sb->cap : CS_SB_INIT;
84 while (ncap < sb->len + extra + SKIP_ONE) {
85 ncap *= PAIR_LEN;
86 }
87 char *grown = (char *)cbm_arena_alloc(sb->a, ncap);
88 if (!grown) {
89 sb->failed = true;
90 return;
91 }
92 if (sb->len > 0) {
93 memcpy(grown, sb->buf, sb->len);
94 }
95 sb->buf = grown;
96 sb->cap = ncap;
97}
98
99static void sb_putn(cs_sb_t *sb, const char *s, size_t n) {
100 sb_reserve(sb, n);

Callers 1

sb_putnFunction · 0.70

Calls 1

cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected