aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-08-31 23:40:19 +0000
committerRichard M. Stallman1996-08-31 23:40:19 +0000
commitc8499ba5d8ec014faa6d81177e1b8d074cd0856e (patch)
tree2657c9d5848c1c2a5491c44d20b02760526c9484
parent590027f7623241b854b68ebe39769078b4f7e1ba (diff)
downloademacs-c8499ba5d8ec014faa6d81177e1b8d074cd0856e.tar.gz
emacs-c8499ba5d8ec014faa6d81177e1b8d074cd0856e.zip
(re_search_2): Optimize regexp that starts with ^.
-rw-r--r--src/regex.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/regex.c b/src/regex.c
index 8ddf63ce495..e82899687e0 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -3284,6 +3284,7 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
3284 register RE_TRANSLATE_TYPE translate = bufp->translate; 3284 register RE_TRANSLATE_TYPE translate = bufp->translate;
3285 int total_size = size1 + size2; 3285 int total_size = size1 + size2;
3286 int endpos = startpos + range; 3286 int endpos = startpos + range;
3287 int anchored_start = 0;
3287 3288
3288 /* Check for out-of-range STARTPOS. */ 3289 /* Check for out-of-range STARTPOS. */
3289 if (startpos < 0 || startpos > total_size) 3290 if (startpos < 0 || startpos > total_size)
@@ -3323,9 +3324,26 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
3323 if (re_compile_fastmap (bufp) == -2) 3324 if (re_compile_fastmap (bufp) == -2)
3324 return -2; 3325 return -2;
3325 3326
3327 /* See whether the pattern is anchored. */
3328 if (bufp->buffer[0] == begline)
3329 anchored_start = 1;
3330
3326 /* Loop through the string, looking for a place to start matching. */ 3331 /* Loop through the string, looking for a place to start matching. */
3327 for (;;) 3332 for (;;)
3328 { 3333 {
3334 /* If the pattern is anchored,
3335 skip quickly past places we cannot match.
3336 We don't bother to treat startpos == 0 specially
3337 because that case doesn't repeat. */
3338 if (anchored_start && startpos > 0)
3339 {
3340 if (! (bufp->newline_anchor
3341 && ((startpos <= size1 ? string1[startpos - 1]
3342 : string2[startpos - size1 - 1])
3343 == '\n')))
3344 goto advance;
3345 }
3346
3329 /* If a fastmap is supplied, skip quickly over characters that 3347 /* If a fastmap is supplied, skip quickly over characters that
3330 cannot be the start of a match. If the pattern can match the 3348 cannot be the start of a match. If the pattern can match the
3331 null string, however, we don't need to skip characters; we want 3349 null string, however, we don't need to skip characters; we want
@@ -3461,7 +3479,7 @@ static boolean alt_match_null_string_p (),
3461 3479
3462/* Free everything we malloc. */ 3480/* Free everything we malloc. */
3463#ifdef MATCH_MAY_ALLOCATE 3481#ifdef MATCH_MAY_ALLOCATE
3464#define FREE_VAR(var) if (var) then { REGEX_FREE (var); var = NULL; } else 3482#define FREE_VAR(var) if (var) { REGEX_FREE (var); var = NULL; } else
3465#define FREE_VARIABLES() \ 3483#define FREE_VARIABLES() \
3466 do { \ 3484 do { \
3467 REGEX_FREE_STACK (fail_stack.stack); \ 3485 REGEX_FREE_STACK (fail_stack.stack); \