diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 17:17:43 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 17:17:43 +0300 |
| commit | 513bf031a589d9e2a1a2730adf56f95e5e316a06 (patch) | |
| tree | 66ef6b095e6aa00c790ac37705fb9df3b099b92a /src/hist.c | |
| parent | 234dd752dc2e15afab38cbbf78f8aa32be72ea5f (diff) | |
Remove unused private functions and inline trivial helpers
Diffstat (limited to 'src/hist.c')
| -rw-r--r-- | src/hist.c | 65 |
1 files changed, 8 insertions, 57 deletions
@@ -106,11 +106,6 @@ static inline bool ring_fit(struct hist *h, uint64_t n) return ring_grow(h, n); } -static inline bool ring_reserve(struct hist *h) -{ - return ring_fit(h, 1); -} - static inline uint64_t cont_at(const struct hist *h, uint32_t i) { return h->cont[(h->cont_first + i) & h->cont_mask]; @@ -756,27 +751,14 @@ void term_hist_runs_emit_slow(struct hist_runs *r) r->len = (uint32_t)(emit_run(r->data + r->len, &r->base, &r->pen, r->count) - r->data); } -static inline void runs_repeat(struct hist_runs *r) -{ - hist_runs_switch(r, text_pen_from_attr(&r->pen)); -} - /* Emit the pending run unless it is a default tail, which readers imply. */ static void runs_finish(struct hist_runs *r) { if (r->count && !pen_attr_is_default(&r->pen)) - runs_repeat(r); + hist_runs_switch(r, text_pen_from_attr(&r->pen)); r->count = 0; } -/* Emit the pending run, default or not, so the next run can use it as its - * delta base. */ -static void runs_flush(struct hist_runs *r) -{ - if (r->count) - runs_repeat(r); -} - /* ---- Encoding ---- */ static inline size_t put_utf8(uint8_t *dst, uint32_t cp) @@ -1310,7 +1292,7 @@ static bool push_line(struct hist *h, const struct cell *cells, int len, const c size_t runs_need = ascii ? RUN_MAX * 2 : (size_t)(len + 2) * RUN_MAX; size_t text_need = ascii ? (size_t)len : (size_t)len * CELL_BYTES; int pg = page_for(h, text_need + runs_need + RUN_MAX); - if (pg < 0 || !ring_reserve(h) || !runs_reserve(&h->runs, runs_need + RUN_MAX)) + if (pg < 0 || !ring_fit(h, 1) || !runs_reserve(&h->runs, runs_need + RUN_MAX)) return false; uint32_t off = h->page_used[pg]; uint8_t *dst = h->pages[pg] + off; @@ -1393,7 +1375,7 @@ static struct hline *begin_line(struct hist *h, size_t need) if (h->lines >= h->line_limit) evict_line(h); int pg = page_for(h, need); - if (pg < 0 || !ring_reserve(h)) + if (pg < 0 || !ring_fit(h, 1)) return NULL; struct hline *p = part(h, h->head++); *p = (struct hline){ @@ -1527,7 +1509,7 @@ static struct hline *open_room(struct hist *h, struct hline *p, size_t text_need h->runs.pen = pen; return p; } - if (!ring_reserve(h)) + if (!ring_fit(h, 1)) return NULL; p = part(h, h->head - 1); p->flags &= (uint8_t)~HLINE_OPEN; @@ -1699,7 +1681,7 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe if (h->lines >= h->line_limit) evict_line(h); int pg = page_for(h, (size_t)row->text_len + rr->len + RUN_MAX); - if (pg < 0 || !ring_reserve(h)) + if (pg < 0 || !ring_fit(h, 1)) return; uint32_t off = h->page_used[pg]; uint8_t *dst = h->pages[pg] + off; @@ -1733,7 +1715,8 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe } /* The runs copy when their delta base is the pen of the open part, else * they are added again pen by pen, which can take more room. */ - runs_flush(&h->runs); + if (h->runs.count) + hist_runs_switch(&h->runs, text_pen_from_attr(&h->runs.pen)); bool copy = pen_attr_equal(&h->runs.base, &row->start); struct hline *q = open_room(h, p, row->text_len, copy ? rr->len + RUN_MAX : runs_need, row->cells); @@ -3153,38 +3136,6 @@ uint64_t term_hist_rows(const struct hist *h, int cols) return total; } -bool term_hist_find_row(const struct hist *h, int target_row, int cols, - uint64_t *out_id, int *out_seg) -{ - if (!h || target_row < 0 || cols <= 0) - return false; - uint64_t total = term_hist_rows(h, cols); - if ((uint64_t)target_row >= total) - return false; - uint64_t id, start; - if ((uint64_t)target_row >= total / 2) { - start = total; - id = hist_end_id(h); - do { - id--; - start -= (uint64_t)term_hist_line_rows(h, id, cols); - } while (start > (uint64_t)target_row && id > h->base_id); - } else { - start = 0; - id = h->base_id; - for (;;) { - uint64_t rows = (uint64_t)term_hist_line_rows(h, id, cols); - if ((uint64_t)target_row < start + rows) - break; - start += rows; - id++; - } - } - *out_id = id; - *out_seg = target_row - (int)start; - return true; -} - /* Locate a row boundary by its cell offset. Wide wrap pads do not count. */ uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols) { @@ -3275,7 +3226,7 @@ bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap) h->page_used = calloc(h->max_pages, sizeof(*h->page_used)); h->page_parts = calloc(h->max_pages, sizeof(*h->page_parts)); h->free_pages = malloc(h->max_pages * sizeof(*h->free_pages)); - if (!h->pages || !h->page_used || !h->page_parts || !h->free_pages || !ring_reserve(h)) { + if (!h->pages || !h->page_used || !h->page_parts || !h->free_pages || !ring_fit(h, 1)) { term_hist_free(h); return false; } |
