summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2020-04-01 08:07:05 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-04-01 10:09:03 +0100
commita5922546ac1e596fc37dc883cff12a9026f68d27 (patch)
treeb0a96a2601fb546c534bb0b95182b25f5c6bdd9b
parent3476eccf48001865ee43f98454d76895158063dc (diff)
Do not go down the regex search path (which is expensive because we need
to convert the grid data into a string for regexec and reverse it to find the grid position) if the search string does not contain any regex special characters.
-rw-r--r--window-copy.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/window-copy.c b/window-copy.c
index c00017b7..8cf499ca 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -2685,23 +2685,27 @@ 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(data->searchstr);
+ wp->searchstr = xstrdup(str);
wp->searchregex = regex;
fx = data->cx;
fy = screen_hsize(data->backing) - data->oy + data->cy;
- screen_init(&ss, screen_write_strlen("%s", data->searchstr), 1, 0);
+ screen_init(&ss, screen_write_strlen("%s", str), 1, 0);
screen_write_start(&ctx, NULL, &ss);
- screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
+ screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", str);
screen_write_stop(&ctx);
wrapflag = options_get_number(wp->window->options, "wrap-search");
- cis = window_copy_is_lowercase(data->searchstr);
+ cis = window_copy_is_lowercase(str);
if (direction) {
window_copy_move_right(s, &fx, &fy, wrapflag);