Patch 9.0.0951 (after 9.0.0950)
Problem:    Trying every character position for a match is inefficient.
Solution:   Use the start position of the match ignoring "\zs".
Files:      src/regexp_nfa.c, src/regexp_bt.c, src/regexp.c, src/regexp.h


*** ../vim-9.0.0950/src/regexp_nfa.c    2022-11-25 21:13:43.179753030 +0000
--- src/regexp_nfa.c    2022-11-26 11:34:01.830736656 +0000
***************
*** 7378,7384 ****
        // If match_text is set it contains the full text that must match.
        // Nothing else to try. Doesn't handle combining chars well.
        if (prog->match_text != NULL && !rex.reg_icombine)
!           return find_match_text(col, prog->regstart, prog->match_text);
      }
  
      // If the start column is past the maximum column: no need to try.
--- 7378,7391 ----
        // If match_text is set it contains the full text that must match.
        // 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
!               rex.reg_match->rm_matchcol = col;
!           return retval;
!       }
      }
  
      // If the start column is past the maximum column: no need to try.
***************
*** 7414,7424 ****
--- 7421,7439 ----
            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
        {
            if (rex.reg_match->endp[0] < rex.reg_match->startp[0])
                rex.reg_match->endp[0] = rex.reg_match->startp[0];
+ 
+           // startpos[0] may be set by "\zs", also return the column where
+           // the whole pattern matched.
+           rex.reg_match->rm_matchcol = col;
        }
      }
  
*** ../vim-9.0.0950/src/regexp_bt.c     2022-09-08 12:17:02.006342437 +0100
--- src/regexp_bt.c     2022-11-26 11:31:11.470918625 +0000
***************
*** 4842,4852 ****
      static long
  bt_regexec_both(
      char_u    *line,
!     colnr_T   col,            // column to start looking for match
      int               *timed_out)     // flag set on timeout or NULL
  {
      bt_regprog_T    *prog;
      char_u        *s;
      long          retval = 0L;
  
      // Create "regstack" and "backpos" if they are not allocated yet.
--- 4842,4853 ----
      static long
  bt_regexec_both(
      char_u    *line,
!     colnr_T   startcol,       // column to start looking for match
      int               *timed_out)     // flag set on timeout or NULL
  {
      bt_regprog_T    *prog;
      char_u        *s;
+     colnr_T       col = startcol;
      long          retval = 0L;
  
      // Create "regstack" and "backpos" if they are not allocated yet.
***************
*** 5042,5052 ****
--- 5043,5061 ----
            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
        {
            if (rex.reg_match->endp[0] < rex.reg_match->startp[0])
                rex.reg_match->endp[0] = rex.reg_match->startp[0];
+ 
+           // startpos[0] may be set by "\zs", also return the column where
+           // the whole pattern matched.
+           rex.reg_match->rm_matchcol = col;
        }
      }
  
*** ../vim-9.0.0950/src/regexp.c        2022-11-25 21:13:43.179753030 +0000
--- src/regexp.c        2022-11-26 11:03:52.706186807 +0000
***************
*** 1123,1132 ****
--- 1123,1134 ----
  typedef struct {
      regmatch_T                *reg_match;
      regmmatch_T               *reg_mmatch;
+ 
      char_u            **reg_startp;
      char_u            **reg_endp;
      lpos_T            *reg_startpos;
      lpos_T            *reg_endpos;
+ 
      win_T             *reg_win;
      buf_T             *reg_buf;
      linenr_T          reg_firstlnum;
*** ../vim-9.0.0950/src/regexp.h        2022-06-05 13:46:55.000000000 +0100
--- src/regexp.h        2022-11-26 11:04:44.769964495 +0000
***************
*** 133,138 ****
--- 133,140 ----
      regprog_T         *regprog;
      char_u            *startp[NSUBEXP];
      char_u            *endp[NSUBEXP];
+ 
+     colnr_T           rm_matchcol;   // match start without "\zs"
      int                       rm_ic;
  } regmatch_T;
  
***************
*** 149,154 ****
--- 151,158 ----
      regprog_T         *regprog;
      lpos_T            startpos[NSUBEXP];
      lpos_T            endpos[NSUBEXP];
+ 
+     colnr_T           rmm_matchcol;   // match start without "\zs"
      int                       rmm_ic;
      colnr_T           rmm_maxcol;     // when not zero: maximum column
  } regmmatch_T;
*** ../vim-9.0.0950/src/version.c       2022-11-25 21:13:43.183753030 +0000
--- src/version.c       2022-11-26 10:55:17.186345279 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     951,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
145. You e-mail your boss, informing him you'll be late.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221126114737.ED1891C091A%40moolenaar.net.

Raspunde prin e-mail lui