summaryrefslogtreecommitdiff
path: root/src/snapshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/snapshot.c')
-rw-r--r--src/snapshot.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/snapshot.c b/src/snapshot.c
index dcd1dc0..3869be4 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -107,9 +107,8 @@ static uint32_t arena_add(struct term_snapshot *s, const struct gstore *g, uint3
if (n <= 0)
return ' ';
if (s->arena_len + (uint32_t)n + 1 > s->arena_cap) {
- uint32_t cap = s->arena_cap ? s->arena_cap * 2 : 256;
- while (cap < s->arena_len + (uint32_t)n + 1)
- cap *= 2;
+ uint32_t cap = term_grow_cap32(s->arena_cap ? s->arena_cap * 2 : 256,
+ s->arena_len + (uint32_t)n + 1);
uint32_t *a = realloc(s->arena, cap * sizeof(*a));
if (!a)
return cps[0];
@@ -228,10 +227,8 @@ static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t)
(size_t)(rows - k) * sizeof(uint32_t));
memmove(s->keys, s->keys + k,
(size_t)(rows - k) * sizeof(uint64_t));
- for (int y = rows - k; y < rows; y++) {
- s->keys[y] = 0;
- s->row_clusters[y] = 0;
- }
+ memset(s->keys + (rows - k), 0, (size_t)k * sizeof(uint64_t));
+ memset(s->row_clusters + (rows - k), 0, (size_t)k * sizeof(uint32_t));
}
for (int y = 0; y < rows; y++) {
@@ -340,7 +337,8 @@ int term_snapshot_cluster(const struct term_snapshot *s, uint32_t text, uint32_t
if (off >= s->arena_len)
return 0;
int n = (int)s->arena[off];
- for (int i = 0; i < n && i < cap; i++)
- cps[i] = s->arena[off + 1 + i];
+ int copy = n < cap ? n : cap;
+ if (copy > 0)
+ memcpy(cps, &s->arena[off + 1], (size_t)copy * sizeof(*cps));
return n;
}