emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1e6463ad22c: (struct gl_state_s): Delete `offset` field


From: Stefan Monnier
Subject: master 1e6463ad22c: (struct gl_state_s): Delete `offset` field
Date: Wed, 12 Apr 2023 15:20:16 -0400 (EDT)

branch: master
commit 1e6463ad22cd74b1b74b9395dff8c8b1485e202e
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (struct gl_state_s): Delete `offset` field
    
    `gl_state` had an `offset` field because:
    
        For buffers, regex-emacs.c passes arguments to the
        UPDATE_SYNTAX_TABLE functions which are relative to BEGV
    
    but the reality is that these arguments are byte offsets relative to
    BEGV_BYTE whereas `offset` was counted in chars, so the two didn't
    cancel each other out.
    
    * src/syntax.h (struct gl_state_s): Delete `offset` field.
    (UPDATE_SYNTAX_TABLE_FORWARD, UPDATE_SYNTAX_TABLE_BACKWARD)
    (SYNTAX_TABLE_BYTE_TO_CHAR):
    * src/syntax.c (SETUP_SYNTAX_TABLE, SETUP_SYNTAX_TABLE_FOR_OBJECT)
    (update_syntax_table, skip_syntaxes): Simplify accordingly.
---
 src/syntax.c | 45 +++++++++++++++++----------------------------
 src/syntax.h | 12 ++++--------
 2 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/src/syntax.c b/src/syntax.c
index 79e16f652f3..8ef13eec40a 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -250,7 +250,6 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
   gl_state.b_property = BEGV;
   gl_state.e_property = ZV + 1;
   gl_state.object = Qnil;
-  gl_state.offset = 0;
   if (parse_sexp_lookup_properties)
     {
       if (count > 0)
@@ -265,12 +264,7 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
 
 /* Same as above, but in OBJECT.  If OBJECT is nil, use current buffer.
    If it is t (which is only used in fast_c_string_match_ignore_case),
-   ignore properties altogether.
-
-   This is meant for regex-emacs.c to use.  For buffers, regex-emacs.c
-   passes arguments to the UPDATE_SYNTAX_TABLE functions which are
-   relative to BEGV.  So if it is a buffer, we set the offset field to
-   BEGV.  */
+   ignore properties altogether.  */
 
 void
 SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
@@ -281,30 +275,26 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
   if (BUFFERP (gl_state.object))
     {
       struct buffer *buf = XBUFFER (gl_state.object);
-      gl_state.b_property = 1;
-      gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1;
-      gl_state.offset = BUF_BEGV (buf) - 1;
+      gl_state.b_property = BEG;
+      gl_state.e_property = BUF_ZV (buf);
     }
   else if (NILP (gl_state.object))
     {
-      gl_state.b_property = 1;
-      gl_state.e_property = ZV - BEGV + 1;
-      gl_state.offset = BEGV - 1;
+      gl_state.b_property = BEG;
+      gl_state.e_property = ZV; /* FIXME: Why not +1 like in 
SETUP_SYNTAX_TABLE? */
     }
   else if (EQ (gl_state.object, Qt))
     {
       gl_state.b_property = 0;
       gl_state.e_property = PTRDIFF_MAX;
-      gl_state.offset = 0;
     }
   else
     {
       gl_state.b_property = 0;
       gl_state.e_property = 1 + SCHARS (gl_state.object);
-      gl_state.offset = 0;
     }
   if (parse_sexp_lookup_properties)
-    update_syntax_table (from + gl_state.offset - (count <= 0),
+    update_syntax_table (from - (count <= 0),
                         count, 1, gl_state.object);
 }
 
@@ -341,8 +331,8 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
       if (!i)
        return;
       i = gl_state.forward_i;
-      gl_state.b_property = i->position - gl_state.offset;
-      gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+      gl_state.b_property = i->position;
+      gl_state.e_property = INTERVAL_LAST_POS (i);
     }
   else
     {
@@ -362,7 +352,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            {
              invalidate = false;
              gl_state.forward_i = i;
-             gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+             gl_state.e_property = INTERVAL_LAST_POS (i);
            }
         }
       else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right.  */
@@ -375,7 +365,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            {
              invalidate = false;
              gl_state.backward_i = i;
-             gl_state.b_property = i->position - gl_state.offset;
+             gl_state.b_property = i->position;
            }
         }
     }
@@ -391,12 +381,12 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
       if (count > 0)
        {
          gl_state.backward_i = i;
-         gl_state.b_property = i->position - gl_state.offset;
+         gl_state.b_property = i->position;
        }
       else
        {
          gl_state.forward_i = i;
-         gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+         gl_state.e_property = INTERVAL_LAST_POS (i);
        }
     }
 
@@ -426,13 +416,13 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
        {
          if (count > 0)
            {
-             gl_state.e_property = i->position - gl_state.offset;
+             gl_state.e_property = i->position;
              gl_state.forward_i = i;
            }
          else
            {
              gl_state.b_property
-               = i->position + LENGTH (i) - gl_state.offset;
+               = i->position + LENGTH (i);
              gl_state.backward_i = i;
            }
          return;
@@ -442,7 +432,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
          if (count > 0)
            {
              gl_state.e_property
-               = i->position + LENGTH (i) - gl_state.offset
+               = i->position + LENGTH (i)
                /* e_property at EOB is not set to ZV but to ZV+1, so that
                   we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
                   having to check eob between the two.  */
@@ -451,7 +441,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            }
          else
            {
-             gl_state.b_property = i->position - gl_state.offset;
+             gl_state.b_property = i->position;
              gl_state.backward_i = i;
            }
          return;
@@ -2201,8 +2191,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, 
Lisp_Object lim)
            while (!parse_sexp_lookup_properties
                   || pos < gl_state.e_property);
 
-           update_syntax_table_forward (pos + gl_state.offset,
-                                        false, gl_state.object);
+           update_syntax_table_forward (pos, false, gl_state.object);
          }
       }
     else
diff --git a/src/syntax.h b/src/syntax.h
index 9eb8701628b..aefe4dafa42 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -85,8 +85,6 @@ struct gl_state_s
                                           and possibly at the
                                           intervals too, depending
                                           on:  */
-  /* Offset for positions specified to UPDATE_SYNTAX_TABLE.  */
-  ptrdiff_t offset;
 };
 
 extern struct gl_state_s gl_state;
@@ -164,10 +162,9 @@ SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos)
          : BUFFERP (gl_state.object)
          ? ((buf_bytepos_to_charpos
              (XBUFFER (gl_state.object),
-              (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1)))
-            - BUF_BEGV (XBUFFER (gl_state.object)) + 1)
+              (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1))))
          : NILP (gl_state.object)
-         ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) - BEGV + 1
+         ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1)
          : bytepos);
 }
 
@@ -178,8 +175,7 @@ INLINE void
 UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos)
 { /* Performs just-in-time syntax-propertization.  */
   if (parse_sexp_lookup_properties && charpos >= gl_state.e_property)
-    update_syntax_table_forward (charpos + gl_state.offset,
-                                false, gl_state.object);
+    update_syntax_table_forward (charpos, false, gl_state.object);
 }
 
 /* Make syntax table state (gl_state) good for CHARPOS, assuming it is
@@ -189,7 +185,7 @@ INLINE void
 UPDATE_SYNTAX_TABLE_BACKWARD (ptrdiff_t charpos)
 {
   if (parse_sexp_lookup_properties && charpos < gl_state.b_property)
-    update_syntax_table (charpos + gl_state.offset, -1, false, 
gl_state.object);
+    update_syntax_table (charpos, -1, false, gl_state.object);
 }
 
 /* Make syntax table good for CHARPOS.  */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]