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@.
This commit is contained in:
nicm 2020-04-01 07:35:10 +00:00
parent b66d62d2d0
commit 89d2a20e56

View File

@ -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);