diff options
| author | Richard M. Stallman | 1994-07-02 00:10:58 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-07-02 00:10:58 +0000 |
| commit | 73e84c9622c276524374542ccc1e3e8d92201a91 (patch) | |
| tree | dcd1ff3640ee9a7118fb46aec5598cf066190187 /src | |
| parent | 904d76247e02548123cd452ca3cab0a0ae0df1f4 (diff) | |
| download | emacs-73e84c9622c276524374542ccc1e3e8d92201a91.tar.gz emacs-73e84c9622c276524374542ccc1e3e8d92201a91.zip | |
(re_compile_fastmap): Either set fastmap['\n'] to 1 or don't change it.
(re_match_2_internal): If the last match is real
best match, don't restore second best one.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/src/regex.c b/src/regex.c index fb829770c54..bd9ad6f6972 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -2855,22 +2855,25 @@ re_compile_fastmap (bufp) | |||
| 2855 | 2855 | ||
| 2856 | 2856 | ||
| 2857 | case anychar: | 2857 | case anychar: |
| 2858 | /* `.' matches anything ... */ | 2858 | { |
| 2859 | for (j = 0; j < (1 << BYTEWIDTH); j++) | 2859 | int fastmap_newline = fastmap['\n']; |
| 2860 | fastmap[j] = 1; | ||
| 2861 | 2860 | ||
| 2862 | /* ... except perhaps newline. */ | 2861 | /* `.' matches anything ... */ |
| 2863 | if (!(bufp->syntax & RE_DOT_NEWLINE)) | 2862 | for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2864 | fastmap['\n'] = 0; | 2863 | fastmap[j] = 1; |
| 2865 | 2864 | ||
| 2866 | /* Return if we have already set `can_be_null'; if we have, | 2865 | /* ... except perhaps newline. */ |
| 2867 | then the fastmap is irrelevant. Something's wrong here. */ | 2866 | if (!(bufp->syntax & RE_DOT_NEWLINE)) |
| 2868 | else if (bufp->can_be_null) | 2867 | fastmap['\n'] = fastmap_newline; |
| 2869 | return 0; | ||
| 2870 | 2868 | ||
| 2871 | /* Otherwise, have to check alternative paths. */ | 2869 | /* Return if we have already set `can_be_null'; if we have, |
| 2872 | break; | 2870 | then the fastmap is irrelevant. Something's wrong here. */ |
| 2871 | else if (bufp->can_be_null) | ||
| 2872 | return 0; | ||
| 2873 | 2873 | ||
| 2874 | /* Otherwise, have to check alternative paths. */ | ||
| 2875 | break; | ||
| 2876 | } | ||
| 2874 | 2877 | ||
| 2875 | #ifdef emacs | 2878 | #ifdef emacs |
| 2876 | case syntaxspec: | 2879 | case syntaxspec: |
| @@ -3598,17 +3601,21 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3598 | longest match, try backtracking. */ | 3601 | longest match, try backtracking. */ |
| 3599 | if (d != end_match_2) | 3602 | if (d != end_match_2) |
| 3600 | { | 3603 | { |
| 3604 | /* 1 if this match ends in the same string (string1 or string2) | ||
| 3605 | as the best previous match. */ | ||
| 3606 | boolean same_str_p = (FIRST_STRING_P (match_end) | ||
| 3607 | == MATCHING_IN_FIRST_STRING); | ||
| 3608 | /* 1 if this match is the best seen so far. */ | ||
| 3609 | boolean best_match_p = (same_str_p ? d > match_end | ||
| 3610 | : !MATCHING_IN_FIRST_STRING); | ||
| 3611 | |||
| 3601 | DEBUG_PRINT1 ("backtracking.\n"); | 3612 | DEBUG_PRINT1 ("backtracking.\n"); |
| 3602 | 3613 | ||
| 3603 | if (!FAIL_STACK_EMPTY ()) | 3614 | if (!FAIL_STACK_EMPTY ()) |
| 3604 | { /* More failure points to try. */ | 3615 | { /* More failure points to try. */ |
| 3605 | boolean same_str_p = (FIRST_STRING_P (match_end) | ||
| 3606 | == MATCHING_IN_FIRST_STRING); | ||
| 3607 | 3616 | ||
| 3608 | /* If exceeds best match so far, save it. */ | 3617 | /* If exceeds best match so far, save it. */ |
| 3609 | if (!best_regs_set | 3618 | if (!best_regs_set || best_match_p) |
| 3610 | || (same_str_p && d > match_end) | ||
| 3611 | || (!same_str_p && !MATCHING_IN_FIRST_STRING)) | ||
| 3612 | { | 3619 | { |
| 3613 | best_regs_set = true; | 3620 | best_regs_set = true; |
| 3614 | match_end = d; | 3621 | match_end = d; |
| @@ -3624,8 +3631,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3624 | goto fail; | 3631 | goto fail; |
| 3625 | } | 3632 | } |
| 3626 | 3633 | ||
| 3627 | /* If no failure points, don't restore garbage. */ | 3634 | /* If no failure points, don't restore garbage. And if |
| 3628 | else if (best_regs_set) | 3635 | last match is real best match, don't restore second |
| 3636 | best one. */ | ||
| 3637 | else if (best_regs_set && !best_match_p) | ||
| 3629 | { | 3638 | { |
| 3630 | restore_best_regs: | 3639 | restore_best_regs: |
| 3631 | /* Restore best match. It may happen that `dend == | 3640 | /* Restore best match. It may happen that `dend == |