summaryrefslogtreecommitdiffstats
path: root/window-copy.c
diff options
context:
space:
mode:
authornicm <nicm>2023-09-04 08:01:43 +0000
committernicm <nicm>2023-09-04 08:01:43 +0000
commit43e5e80343185e69a1b864fc48095ede0b898180 (patch)
treebafc0550deccb94c127312c82da9e3f2ebf72e9e /window-copy.c
parentc767d62329597b9152c0e1b33ba2656be8e0bced (diff)
Skip wrapped lines in top level search loop because they will be
combined in the inner loop (in window_copy_search_rl_regex and the others), avoids searching the same text multiple times. Also add a line length limit for regex searches. GitHub issue 3675.
Diffstat (limited to 'window-copy.c')
-rw-r--r--window-copy.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/window-copy.c b/window-copy.c
index 1c8a326d..6f233077 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -295,6 +295,7 @@ struct window_copy_mode_data {
int timeout; /* search has timed out */
#define WINDOW_COPY_SEARCH_TIMEOUT 10000
#define WINDOW_COPY_SEARCH_ALL_TIMEOUT 200
+#define WINDOW_COPY_SEARCH_MAX_LINE 2000
int jumptype;
struct utf8_data *jumpchar;
@@ -3205,7 +3206,9 @@ window_copy_search_lr_regex(struct grid *gd, u_int *ppx, u_int *psx, u_int py,
len = gd->sx - first;
endline = gd->hsize + gd->sy - 1;
pywrap = py;
- while (buf != NULL && pywrap <= endline) {
+ while (buf != NULL &&
+ pywrap <= endline &&
+ len < WINDOW_COPY_SEARCH_MAX_LINE) {
gl = grid_get_line(gd, pywrap);
if (~gl->flags & GRID_LINE_WRAPPED)
break;
@@ -3262,7 +3265,9 @@ window_copy_search_rl_regex(struct grid *gd, u_int *ppx, u_int *psx, u_int py,
len = gd->sx - first;
endline = gd->hsize + gd->sy - 1;
pywrap = py;
- while (buf != NULL && (pywrap <= endline)) {
+ while (buf != NULL &&
+ pywrap <= endline &&
+ len < WINDOW_COPY_SEARCH_MAX_LINE) {
gl = grid_get_line(gd, pywrap);
if (~gl->flags & GRID_LINE_WRAPPED)
break;
@@ -3601,10 +3606,11 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
struct grid *sgd, u_int fx, u_int fy, u_int endline, int cis, int wrap,
int direction, int regex)
{
- u_int i, px, sx, ssize = 1;
- int found = 0, cflags = REG_EXTENDED;
- char *sbuf;
- regex_t reg;
+ u_int i, px, sx, ssize = 1;
+ int found = 0, cflags = REG_EXTENDED;
+ char *sbuf;
+ regex_t reg;
+ struct grid_line *gl;
if (regex) {
sbuf = xmalloc(ssize);
@@ -3621,6 +3627,9 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
if (direction) {
for (i = fy; i <= endline; i++) {
+ gl = grid_get_line(gd, i);
+ if (i != endline && gl->flags & GRID_LINE_WRAPPED)
+ continue;
if (regex) {
found = window_copy_search_lr_regex(gd,
&px, &sx, i, fx, gd->sx, &reg);
@@ -3634,6 +3643,9 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
}
} else {
for (i = fy + 1; endline < i; i--) {
+ gl = grid_get_line(gd, i - 1);
+ if (i != endline && gl->flags & GRID_LINE_WRAPPED)
+ continue;
if (regex) {
found = window_copy_search_rl_regex(gd,
&px, &sx, i - 1, 0, fx + 1, &reg);