comparison 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
comparison
equal deleted inserted replaced
31234:e841d465ff3d 31235:7fb4e244b16e
7376 return 0L; 7376 return 0L;
7377 7377
7378 // If match_text is set it contains the full text that must match. 7378 // If match_text is set it contains the full text that must match.
7379 // Nothing else to try. Doesn't handle combining chars well. 7379 // Nothing else to try. Doesn't handle combining chars well.
7380 if (prog->match_text != NULL && !rex.reg_icombine) 7380 if (prog->match_text != NULL && !rex.reg_icombine)
7381 return find_match_text(col, prog->regstart, prog->match_text); 7381 {
7382 retval = find_match_text(col, prog->regstart, prog->match_text);
7383 if (REG_MULTI)
7384 rex.reg_mmatch->rmm_matchcol = col;
7385 else
7386 rex.reg_match->rm_matchcol = col;
7387 return retval;
7388 }
7382 } 7389 }
7383 7390
7384 // If the start column is past the maximum column: no need to try. 7391 // If the start column is past the maximum column: no need to try.
7385 if (rex.reg_maxcol > 0 && col >= rex.reg_maxcol) 7392 if (rex.reg_maxcol > 0 && col >= rex.reg_maxcol)
7386 goto theend; 7393 goto theend;
7412 lpos_T *end = &rex.reg_mmatch->endpos[0]; 7419 lpos_T *end = &rex.reg_mmatch->endpos[0];
7413 7420
7414 if (end->lnum < start->lnum 7421 if (end->lnum < start->lnum
7415 || (end->lnum == start->lnum && end->col < start->col)) 7422 || (end->lnum == start->lnum && end->col < start->col))
7416 rex.reg_mmatch->endpos[0] = rex.reg_mmatch->startpos[0]; 7423 rex.reg_mmatch->endpos[0] = rex.reg_mmatch->startpos[0];
7424
7425 // startpos[0] may be set by "\zs", also return the column where
7426 // the whole pattern matched.
7427 rex.reg_mmatch->rmm_matchcol = col;
7417 } 7428 }
7418 else 7429 else
7419 { 7430 {
7420 if (rex.reg_match->endp[0] < rex.reg_match->startp[0]) 7431 if (rex.reg_match->endp[0] < rex.reg_match->startp[0])
7421 rex.reg_match->endp[0] = rex.reg_match->startp[0]; 7432 rex.reg_match->endp[0] = rex.reg_match->startp[0];
7433
7434 // startpos[0] may be set by "\zs", also return the column where
7435 // the whole pattern matched.
7436 rex.reg_match->rm_matchcol = col;
7422 } 7437 }
7423 } 7438 }
7424 7439
7425 return retval; 7440 return retval;
7426 } 7441 }