>From 04435ddc85dd7b126571417a5daf09e28dd39f7c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 1 Aug 2018 19:13:08 -0700 Subject: [PATCH 4/4] Remove always-0 struct re_pattern_buffer members * src/regex-emacs.h (struct re_pattern_buffer): Remove no_sub, not_bol, not_eol. They are always zero. All uses removed, and code simplified. --- src/regex-emacs.c | 42 +++++++++++------------------------------- src/regex-emacs.h | 15 ++------------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/src/regex-emacs.c b/src/regex-emacs.c index c2582281da..747874b826 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -762,9 +762,6 @@ print_compiled_pattern (struct re_pattern_buffer *bufp) printf ("re_nsub: %zu\t", bufp->re_nsub); printf ("regs_alloc: %d\t", bufp->regs_allocated); printf ("can_be_null: %d\t", bufp->can_be_null); - printf ("no_sub: %d\t", bufp->no_sub); - printf ("not_bol: %d\t", bufp->not_bol); - printf ("not_eol: %d\t", bufp->not_eol); #ifndef emacs printf ("syntax: %lx\n", bufp->syntax); #endif @@ -1682,7 +1679,6 @@ static bool group_in_compile_stack (compile_stack_type, regnum_t); `used' is set to the length of the compiled pattern; `fastmap_accurate' is zero; `re_nsub' is the number of subexpressions in PATTERN; - `not_bol' and `not_eol' are zero; The `fastmap' field is neither examined nor set. */ @@ -1786,7 +1782,6 @@ regex_compile (re_char *pattern, size_t size, /* Initialize the pattern buffer. */ bufp->fastmap_accurate = 0; - bufp->not_bol = bufp->not_eol = 0; bufp->used_syntax = 0; /* Set `used' to zero, so that if we return an error, the pattern @@ -1794,7 +1789,6 @@ regex_compile (re_char *pattern, size_t size, at the end. */ bufp->used = 0; - /* Always count groups, whether or not bufp->no_sub is set. */ bufp->re_nsub = 0; if (bufp->allocated == 0) @@ -3840,9 +3834,8 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, and SIZE2, respectively). We start matching at POS, and stop matching at STOP. - If REGS is non-null and the `no_sub' field of BUFP is nonzero, we - store offsets for the substring each group matched in REGS. See the - documentation for exactly how many groups we fill. + If REGS is non-null, store offsets for the substring each group + matched in REGS. We return -1 if no match, -2 if an internal error (such as the failure stack overflowing). Otherwise, we return the length of the @@ -4129,7 +4122,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, DEBUG_PRINT ("Accepting match.\n"); /* If caller wants register contents data back, do it. */ - if (regs && !bufp->no_sub) + if (regs) { /* Have the register data arrays been allocated? */ if (bufp->regs_allocated == REGS_UNALLOCATED) @@ -4184,7 +4177,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, -1 at the end. */ for (reg = num_regs; reg < regs->num_regs; reg++) regs->start[reg] = regs->end[reg] = -1; - } /* regs && !bufp->no_sub */ + } DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n", nfailure_points_pushed, nfailure_points_popped, @@ -4481,15 +4474,13 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, break; - /* begline matches the empty string at the beginning of the string - (unless `not_bol' is set in `bufp'), and after newlines. */ + /* begline matches the empty string at the beginning of the string, + and after newlines. */ case begline: DEBUG_PRINT ("EXECUTING begline.\n"); if (AT_STRINGS_BEG (d)) - { - if (!bufp->not_bol) break; - } + break; else { unsigned c; @@ -4497,7 +4488,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, if (c == '\n') break; } - /* In all other cases, we fail. */ goto fail; @@ -4506,15 +4496,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, DEBUG_PRINT ("EXECUTING endline.\n"); if (AT_STRINGS_END (d)) - { - if (!bufp->not_eol) break; - } - else - { - PREFETCH_NOLIMIT (); - if (*d == '\n') - break; - } + break; + PREFETCH_NOLIMIT (); + if (*d == '\n') + break; goto fail; @@ -5112,11 +5097,6 @@ re_compile_pattern (const char *pattern, size_t length, (and at least one extra will be -1). */ bufp->regs_allocated = REGS_UNALLOCATED; - /* And GNU code determines whether or not to get register information - by passing null for the REGS argument to re_search, etc., not by - setting no_sub. */ - bufp->no_sub = 0; - ret = regex_compile ((re_char *) pattern, length, posix_backtracking, whitespace_regexp, diff --git a/src/regex-emacs.h b/src/regex-emacs.h index 898c0f2aea..4dabe680ef 100644 --- a/src/regex-emacs.h +++ b/src/regex-emacs.h @@ -60,7 +60,7 @@ extern ptrdiff_t emacs_re_safe_alloca; /* This data structure represents a compiled pattern. Before calling the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been + and `translate' can be set. After the pattern has been compiled, the `re_nsub' field is available. All other fields are private to the regex routines. */ @@ -110,17 +110,6 @@ struct re_pattern_buffer by `re_compile_fastmap' if it updates the fastmap. */ unsigned fastmap_accurate : 1; - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - /* If true, the compilation of the pattern had to look up the syntax table, so the compiled pattern is only valid for the current syntax table. */ unsigned used_syntax : 1; @@ -149,7 +138,7 @@ extern const char *re_compile_pattern (const char *pattern, size_t length, compiled into BUFFER. Start searching at position START, for RANGE characters. Return the starting position of the match, -1 for no match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ + information in REGS (if REGS is nonzero). */ extern ptrdiff_t re_search (struct re_pattern_buffer *buffer, const char *string, size_t length, ptrdiff_t start, ptrdiff_t range, -- 2.17.1