summaryrefslogtreecommitdiff
path: root/src/selection.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 19:41:47 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 19:41:47 +0300
commit1b52f704a005d79d00b1260b1e5bc5d6798ff7b6 (patch)
tree798c93f1007d0156635d9db63d47ae9a6328dd80 /src/selection.c
parent01e1c61e9fcf4a0b0164a7fe5395a209a50f6905 (diff)
Replace scalar loops with SIMD spans, packed stores, and direct wrap-pad checks
Diffstat (limited to 'src/selection.c')
-rw-r--r--src/selection.c20
1 files changed, 13 insertions, 7 deletions
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)