diff src/regexp_nfa.c @ 31235:7fb4e244b16e v9.0.0951

patch 9.0.0951: trying every character position for a match is inefficient Commit: https://github.com/vim/vim/commit/01105b37a108022515d364201767f7f111ec4222 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 26 11:47:10 2022 +0000 patch 9.0.0951: trying every character position for a match is inefficient Problem: Trying every character position for a match is inefficient. Solution: Use the start position of the match ignoring "\zs".
author Bram Moolenaar <Bram@vim.org>
date Sat, 26 Nov 2022 13:00:05 +0100
parents d80066065462
children fa309d9af73c
line wrap: on
line diff
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -7378,7 +7378,14 @@ nfa_regexec_both(
 	// 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);
+	{
+	    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,11 +7421,19 @@ theend:
 	    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;
 	}
     }