summaryrefslogtreecommitdiff
path: root/src/gstore.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
commitbdaedce69b17b654bd0060579dd9b9ff120009b5 (patch)
tree0e9cd8597652263a96c48ba678fb0b66e1fc131b /src/gstore.c
parentba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff)
parentdcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff)
Merge branch 'wt/rename' into api-hardening
# Conflicts: # README.md
Diffstat (limited to 'src/gstore.c')
-rw-r--r--src/gstore.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/gstore.c b/src/gstore.c
index 813ea7d..a94af32 100644
--- a/src/gstore.c
+++ b/src/gstore.c
@@ -29,7 +29,7 @@ struct gslot {
};
struct gstore {
- struct term *term;
+ struct wsap_vtcore *term;
uint32_t *arena;
size_t arena_len;
size_t arena_cap;
@@ -68,15 +68,15 @@ static inline bool gentry_matches(const struct gstore *g, const struct gentry *e
return !memcmp(&g->arena[e->offset], &cps[2], (size_t)(n - 2) * sizeof(*cps));
}
-int term_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap)
+int wsap_vtcore_gstore_expand(const struct gstore *g, uint32_t handle, uint32_t *cps, int cap)
{
if (cap <= 0)
return 0;
- if (!g || !term_grapheme_is_handle(handle)) {
+ if (!g || !wsap_vtcore_grapheme_is_handle(handle)) {
cps[0] = handle;
return 1;
}
- uint32_t idx = handle - TERM_GRAPHEME_HANDLE_BASE;
+ uint32_t idx = handle - WSAP_VTCORE_GRAPHEME_HANDLE_BASE;
if (idx >= g->entries_count || !g->entries[idx].allocated) {
cps[0] = 0xFFFD;
return 1;
@@ -124,8 +124,8 @@ static bool grow_slots(struct gstore *g)
struct gentry *e = &g->entries[i];
if (!e->allocated)
continue;
- uint32_t cps_buf[TERM_GRAPHEME_MAX_LEN];
- int n = term_gstore_expand(g, TERM_GRAPHEME_HANDLE_BASE + i, cps_buf, TERM_GRAPHEME_MAX_LEN);
+ uint32_t cps_buf[WSAP_VTCORE_GRAPHEME_MAX_LEN];
+ int n = wsap_vtcore_gstore_expand(g, WSAP_VTCORE_GRAPHEME_HANDLE_BASE + i, cps_buf, WSAP_VTCORE_GRAPHEME_MAX_LEN);
uint64_t h = hash_cps(cps_buf, n);
uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1;
gstore_insert_slot(g, h32, i);
@@ -147,14 +147,14 @@ static uint32_t gstore_find(const struct gstore *g, const uint32_t *cps, int n,
uint32_t e_idx = slot->entry_idx - 1;
const struct gentry *e = &g->entries[e_idx];
if (e->allocated && gentry_matches(g, e, cps, n))
- return TERM_GRAPHEME_HANDLE_BASE + e_idx;
+ return WSAP_VTCORE_GRAPHEME_HANDLE_BASE + e_idx;
}
idx = (idx + 1) & mask;
}
return 0;
}
-struct gstore *term_gstore_new(struct term *t)
+struct gstore *wsap_vtcore_gstore_new(struct wsap_vtcore *t)
{
struct gstore *g = calloc(1, sizeof(*g));
if (!g)
@@ -164,7 +164,7 @@ struct gstore *term_gstore_new(struct term *t)
return g;
}
-void term_gstore_free(struct gstore *g)
+void wsap_vtcore_gstore_free(struct gstore *g)
{
if (!g)
return;
@@ -174,28 +174,28 @@ void term_gstore_free(struct gstore *g)
free(g);
}
-uint32_t term_gstore_count(const struct gstore *g)
+uint32_t wsap_vtcore_gstore_count(const struct gstore *g)
{
return g ? g->live_count : 0;
}
-void term_gstore_pin(struct gstore *g)
+void wsap_vtcore_gstore_pin(struct gstore *g)
{
if (g)
g->pin_depth++;
}
-void term_gstore_unpin(struct gstore *g)
+void wsap_vtcore_gstore_unpin(struct gstore *g)
{
if (g && g->pin_depth > 0)
g->pin_depth--;
}
-void term_gstore_mark(struct gstore *g, uint32_t handle)
+void wsap_vtcore_gstore_mark(struct gstore *g, uint32_t handle)
{
- if (!g || !term_grapheme_is_handle(handle))
+ if (!g || !wsap_vtcore_grapheme_is_handle(handle))
return;
- uint32_t idx = handle - TERM_GRAPHEME_HANDLE_BASE;
+ uint32_t idx = handle - WSAP_VTCORE_GRAPHEME_HANDLE_BASE;
if (idx < g->entries_count && g->entries[idx].allocated)
g->entries[idx].mark = true;
}
@@ -204,19 +204,19 @@ static void sweep_mark_row(struct gstore *g, const struct cell *cells, int len)
{
for (int x = 0; x < len; x++) {
uint32_t c = cells[x].c;
- if (term_grapheme_is_handle(c))
- term_gstore_mark(g, c);
+ if (wsap_vtcore_grapheme_is_handle(c))
+ wsap_vtcore_gstore_mark(g, c);
}
}
-void term_gstore_sweep(struct gstore *g, struct term *t)
+void wsap_vtcore_gstore_sweep(struct gstore *g, struct wsap_vtcore *t)
{
if (!g)
return;
if (t) {
- if (term_grapheme_is_handle(t->last_char))
- term_gstore_mark(g, t->last_char);
+ if (wsap_vtcore_grapheme_is_handle(t->last_char))
+ wsap_vtcore_gstore_mark(g, t->last_char);
struct screen *s = &t->scr;
for (int y = 0; y < s->rows; y++) {
@@ -266,8 +266,8 @@ void term_gstore_sweep(struct gstore *g, struct term *t)
live++;
e->mark = false;
if (g->slots) {
- uint32_t cps_buf[TERM_GRAPHEME_MAX_LEN];
- int n = term_gstore_expand(g, TERM_GRAPHEME_HANDLE_BASE + i, cps_buf, TERM_GRAPHEME_MAX_LEN);
+ uint32_t cps_buf[WSAP_VTCORE_GRAPHEME_MAX_LEN];
+ int n = wsap_vtcore_gstore_expand(g, WSAP_VTCORE_GRAPHEME_HANDLE_BASE + i, cps_buf, WSAP_VTCORE_GRAPHEME_MAX_LEN);
uint64_t h = hash_cps(cps_buf, n);
uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1;
gstore_insert_slot(g, h32, i);
@@ -294,14 +294,14 @@ void term_gstore_sweep(struct gstore *g, struct term *t)
g->sweep_threshold = 1024;
}
-uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n)
+uint32_t wsap_vtcore_gstore_intern(struct gstore *g, const uint32_t *cps, int n)
{
if (!g || n <= 0)
return 0;
if (n == 1)
return cps[0];
- if (n > TERM_GRAPHEME_MAX_LEN)
- n = TERM_GRAPHEME_MAX_LEN;
+ if (n > WSAP_VTCORE_GRAPHEME_MAX_LEN)
+ n = WSAP_VTCORE_GRAPHEME_MAX_LEN;
uint64_t h = hash_cps(cps, n);
uint32_t h32 = (uint32_t)h ? (uint32_t)h : 1;
@@ -313,7 +313,7 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n)
if (g->term && g->pin_depth == 0 &&
(g->live_count >= g->sweep_threshold ||
g->live_count >= GSTORE_MAX_ENTRIES)) {
- term_gstore_sweep(g, g->term);
+ wsap_vtcore_gstore_sweep(g, g->term);
existing = gstore_find(g, cps, n, h32);
if (existing)
return existing;
@@ -355,7 +355,7 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n)
if (n > 2) {
size_t extra = (size_t)(n - 2);
if (g->arena_len + extra > g->arena_cap) {
- size_t new_cap = term_grow_cap(g->arena_cap ? g->arena_cap * 2 : 512,
+ size_t new_cap = wsap_vtcore_grow_cap(g->arena_cap ? g->arena_cap * 2 : 512,
g->arena_len + extra);
uint32_t *next = realloc(g->arena, new_cap * sizeof(*next));
if (!next) {
@@ -375,5 +375,5 @@ uint32_t term_gstore_intern(struct gstore *g, const uint32_t *cps, int n)
gstore_insert_slot(g, h32, entry_idx);
g->live_count++;
- return TERM_GRAPHEME_HANDLE_BASE + entry_idx;
+ return WSAP_VTCORE_GRAPHEME_HANDLE_BASE + entry_idx;
}