From 861cf3a5c9d2081d811dcfc2c5ce5357f3dc44d4 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 12 Apr 2023 16:32:39 -0400 Subject: [PATCH] (RE_SETUP_SYNTAX_TABLE_FOR_OBJECT): Simplify It turns out all calls to this function pass the same value for the `count` argument, and they're all in `regexp.c`. * src/syntax.c (RE_SETUP_SYNTAX_TABLE_FOR_OBJECT): Rename from `SETUP_SYNTAX_TABLE_FOR_OBJECT`. Remove `count` argument. Move call to `RE_SYNTAX_TABLE_BYTE_TO_CHAR` to where its result is actually used. * src/regex-emacs.c (re_search_2, re_match_2): Adjust accordingly. * src/syntax.h (RE_SYNTAX_TABLE_BYTE_TO_CHAR): Rename from `SYNTAX_TABLE_BYTE_TO_CHAR` to clarify that it takes a byteoffset as used in the regexp engine and not a "bytepos". Adjust all callers. --- src/regex-emacs.c | 16 ++++++++-------- src/syntax.c | 9 ++++----- src/syntax.h | 8 ++++---- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 83caeca2464..746779490ad 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -3251,7 +3251,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, ptrdiff_t size1, /* See whether the pattern is anchored. */ anchored_start = (bufp->buffer[0] == begline); - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos, 1); + RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos); /* Loop through the string, looking for a place to start matching. */ for (;;) @@ -3859,7 +3859,7 @@ re_match_2 (struct re_pattern_buffer *bufp, { ptrdiff_t result; - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos, 1); + RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos); result = re_match_2_internal (bufp, (re_char *) string1, size1, (re_char *) string2, size2, @@ -4792,7 +4792,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4832,7 +4832,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); GET_CHAR_AFTER (c2, d, dummy); @@ -4875,7 +4875,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4917,7 +4917,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); c2 = RE_STRING_CHAR (d, target_multibyte); @@ -4958,7 +4958,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4994,7 +4994,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, PREFETCH (); { ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t pos1 = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (pos1); } { diff --git a/src/syntax.c b/src/syntax.c index c1caaa8a739..e9e04e2d638 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -268,12 +268,11 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) FROMBYTE is an regexp-byteoffset. */ void -SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, - ptrdiff_t frombyte, ptrdiff_t count) +RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, + ptrdiff_t frombyte) { SETUP_BUFFER_SYNTAX_TABLE (); gl_state.object = object; - ptrdiff_t from = SYNTAX_TABLE_BYTE_TO_CHAR (frombyte); if (BUFFERP (gl_state.object)) { struct buffer *buf = XBUFFER (gl_state.object); @@ -296,8 +295,8 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, gl_state.e_property = 1 + SCHARS (gl_state.object); } if (parse_sexp_lookup_properties) - update_syntax_table (from - (count <= 0), - count, 1, gl_state.object); + update_syntax_table (RE_SYNTAX_TABLE_BYTE_TO_CHAR (frombyte), + 1, 1, gl_state.object); } /* Update gl_state to an appropriate interval which contains CHARPOS. The diff --git a/src/syntax.h b/src/syntax.h index 05d58eff05f..01982be25a0 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -145,15 +145,15 @@ extern bool syntax_prefix_flag_p (int c); extern unsigned char const syntax_spec_code[0400]; -/* Convert the regexp BYTEOFFSET into a character position, - for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT. +/* Convert the regexp's BYTEOFFSET into a character position, + for the object recorded in gl_state with RE_SETUP_SYNTAX_TABLE_FOR_OBJECT. The value is meant for use in code that does nothing when parse_sexp_lookup_properties is false, so return 0 in that case, for speed. */ INLINE ptrdiff_t -SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset) +RE_SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset) { return (! parse_sexp_lookup_properties ? 0 @@ -208,7 +208,7 @@ SETUP_BUFFER_SYNTAX_TABLE (void) } extern ptrdiff_t scan_words (ptrdiff_t, EMACS_INT); -extern void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t, ptrdiff_t); +extern void RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t); INLINE_HEADER_END -- 2.39.2