To: vim_dev@googlegroups.com Subject: Patch 9.0.1047 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1047 Problem: Matchparen is slow. Solution: Actually use the position where the match started, not the position where the search started. (closes #11644) Files: src/regexp_nfa.c *** ../vim-9.0.1046/src/regexp_nfa.c 2022-11-30 18:11:52.694904295 +0000 --- src/regexp_nfa.c 2022-12-11 14:15:32.745156675 +0000 *************** *** 3943,3948 **** --- 3943,3949 ---- char_u *end; } line[NSUBEXP]; } list; + colnr_T orig_start_col; // list.multi[0].start_col without \zs } regsub_T; typedef struct *************** *** 4099,4107 **** --- 4100,4111 ---- { // Copy the match start and end positions. if (REG_MULTI) + { mch_memmove(&to->list.multi[0], &from->list.multi[0], sizeof(struct multipos) * from->in_use); + to->orig_start_col = from->orig_start_col; + } else mch_memmove(&to->list.line[0], &from->list.line[0], *************** *** 5621,5629 **** * Returns zero for no match, 1 for a match. */ static long ! find_match_text(colnr_T startcol, int regstart, char_u *match_text) { ! colnr_T col = startcol; int c1, c2; int len1, len2; int match; --- 5625,5633 ---- * Returns zero for no match, 1 for a match. */ static long ! find_match_text(colnr_T *startcol, int regstart, char_u *match_text) { ! colnr_T col = *startcol; int c1, c2; int len1, len2; int match; *************** *** 5662,5667 **** --- 5666,5672 ---- rex.reg_startp[0] = rex.line + col; rex.reg_endp[0] = rex.line + col + len2; } + *startcol = col; return 1L; } *************** *** 5670,5675 **** --- 5675,5682 ---- if (skip_to_start(regstart, &col) == FAIL) break; } + + *startcol = col; return 0L; } *************** *** 5777,5782 **** --- 5784,5790 ---- { m->norm.list.multi[0].start_lnum = rex.lnum; m->norm.list.multi[0].start_col = (colnr_T)(rex.input - rex.line); + m->norm.orig_start_col = m->norm.list.multi[0].start_col; } else m->norm.list.line[0].start = rex.input; *************** *** 7081,7088 **** --- 7089,7100 ---- if (add) { if (REG_MULTI) + { m->norm.list.multi[0].start_col = (colnr_T)(rex.input - rex.line) + clen; + m->norm.orig_start_col = + m->norm.list.multi[0].start_col; + } else m->norm.list.line[0].start = rex.input + clen; if (addstate(nextlist, start->out, m, NULL, clen) == NULL) *************** *** 7218,7223 **** --- 7230,7237 ---- rex.reg_endpos[i].lnum = subs.norm.list.multi[i].end_lnum; rex.reg_endpos[i].col = subs.norm.list.multi[i].end_col; } + if (rex.reg_mmatch != NULL) + rex.reg_mmatch->rmm_matchcol = subs.norm.orig_start_col; if (rex.reg_startpos[0].lnum < 0) { *************** *** 7379,7385 **** // Nothing else to try. Doesn't handle combining chars well. if (prog->match_text != NULL && !rex.reg_icombine) { ! retval = find_match_text(col, prog->regstart, prog->match_text); if (REG_MULTI) rex.reg_mmatch->rmm_matchcol = col; else --- 7393,7399 ---- // Nothing else to try. Doesn't handle combining chars well. if (prog->match_text != NULL && !rex.reg_icombine) { ! retval = find_match_text(&col, prog->regstart, prog->match_text); if (REG_MULTI) rex.reg_mmatch->rmm_matchcol = col; else *************** *** 7421,7430 **** if (end->lnum < start->lnum || (end->lnum == start->lnum && end->col < start->col)) rex.reg_mmatch->endpos[0] = rex.reg_mmatch->startpos[0]; - - // startpos[0] may be set by "\zs", also return the column where - // the whole pattern matched. - rex.reg_mmatch->rmm_matchcol = col; } else { --- 7435,7440 ---- *** ../vim-9.0.1046/src/version.c 2022-12-10 19:03:48.044388086 +0000 --- src/version.c 2022-12-11 13:49:01.227397828 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1047, /**/ -- They now pass three KNIGHTS impaled to a tree. With their feet off the ground, with one lance through the lot of them, they are skewered up like a barbecue. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///