From 1b52f704a005d79d00b1260b1e5bc5d6798ff7b6 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 19:41:47 +0300 Subject: Replace scalar loops with SIMD spans, packed stores, and direct wrap-pad checks --- src/selection.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/selection.c') diff --git a/src/selection.c b/src/selection.c index 4602d8f..e4a3e35 100644 --- a/src/selection.c +++ b/src/selection.c @@ -26,7 +26,15 @@ static char *link_at_text(const struct term *t, struct term_vector2i cell) while (end < t->cols && cells[end].c > ' ' && cells[end].c < 127) end++; char *text = malloc((size_t)(end - start) + 1); if (!text) return NULL; - for (int c = start; c < end; c++) text[c - start] = cells[c].c; + int c = start; + for (; c + 4 <= end; c += 4) { + uint32_t packed = (cells[c].c & 0xff) | + ((cells[c + 1].c & 0xff) << 8) | + ((cells[c + 2].c & 0xff) << 16) | + ((cells[c + 3].c & 0xff) << 24); + memcpy(text + (c - start), &packed, 4); + } + for (; c < end; c++) text[c - start] = (char)cells[c].c; text[end - start] = 0; size_t scheme = 8; char *url = strstr(text, "https://"); @@ -307,9 +315,8 @@ static struct term_sel_point view_to_sel_point(const struct lines *L, int x, int if (!view_row_line(L, y, &id, &seg)) return (struct term_sel_point){ .line_id = L->first }; const struct cell *cells = line_seg_cells(L, id, seg, NULL, NULL); - if (cells) - while (x > 0 && (cells[x].flags & CELL_WRAP_PAD)) - x--; + if (cells && x > 0 && (cells[x].flags & CELL_WRAP_PAD)) + x--; return (struct term_sel_point){ .line_id = id, .cell_off = line_seg_start_off(L, id, seg) + (uint32_t)x, @@ -385,9 +392,8 @@ static void unit_span(const struct lines *L, int x, int y, bool right_half, } const struct cell *row = term_screen_view_row(t, y); - if (row) - while (x > 0 && (row[x].flags & CELL_WRAP_PAD)) - x--; + if (row && x > 0 && (row[x].flags & CELL_WRAP_PAD)) + x--; int left = x, right = x; int kind = row ? word_class(row[x].c) : 0; while (left > 0 && row && word_class(row[left - 1].c) == kind) -- cgit v1.2.3