summaryrefslogtreecommitdiffstats
path: root/window-copy.c
diff options
context:
space:
mode:
authornicm <nicm>2020-04-01 07:35:10 +0000
committernicm <nicm>2020-04-01 07:35:10 +0000
commit89d2a20e561878f3fee11005369c1d56b9a08c38 (patch)
tree01dde7c07c6a243833cd130206eb1c9b7fdf4cfe /window-copy.c
parentb66d62d2d05fcb889680c5d844d68ffcef6e9689 (diff)
Performance improvements for regex searching, most notably:
- Use the grid data directly instead of copying it. - Special case the most typical one byte character cells and use memcmp for multiple bytes instead of a handrolled loop. - Hoist regcomp out of the loop into the calling functions. GitHub issue 2143. Also a man page from from jmc@.
Diffstat (limited to 'window-copy.c')
-rw-r--r--window-copy.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/window-copy.c b/window-copy.c
index 8c226a92..57228273 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -2523,9 +2523,8 @@ window_copy_cstrtocellpos(struct grid *gd, u_int ncells, u_int *ppx, u_int *ppy,
cells[cell].d = window_copy_cellstring(gl, px,
&cells[cell].dlen);
cell++;
- px++;
- if (px == gd->sx) {
- px = 0;
+ px = (px + 1) % gd->sx;
+ if (px == 0) {
pywrap++;
gl = grid_peek_line(gd, pywrap);
}
@@ -2714,27 +2713,23 @@ window_copy_search(struct window_mode_entry *wme, int direction, int regex)
struct screen *s = data->backing, ss;
struct screen_write_ctx ctx;
struct grid *gd = s->grid;
- const char *str = data->searchstr;
u_int fx, fy, endline;
int wrapflag, cis, found;
- if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0')
- regex = 0;
-
free(wp->searchstr);
- wp->searchstr = xstrdup(str);
+ wp->searchstr = xstrdup(data->searchstr);
wp->searchregex = regex;
fx = data->cx;
fy = screen_hsize(data->backing) - data->oy + data->cy;
- screen_init(&ss, screen_write_strlen("%s", str), 1, 0);
+ screen_init(&ss, screen_write_strlen("%s", data->searchstr), 1, 0);
screen_write_start(&ctx, NULL, &ss);
- screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", str);
+ screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
screen_write_stop(&ctx);
wrapflag = options_get_number(wp->window->options, "wrap-search");
- cis = window_copy_is_lowercase(str);
+ cis = window_copy_is_lowercase(data->searchstr);
if (direction) {
window_copy_move_right(s, &fx, &fy, wrapflag);