emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 8a247f6 2/2: Simplify validate_interval_range and c


From: Paul Eggert
Subject: [Emacs-diffs] master 8a247f6 2/2: Simplify validate_interval_range and callers
Date: Wed, 12 Dec 2018 12:55:52 -0500 (EST)

branch: master
commit 8a247f6059066636fbb60e79f6a9580ee9a81495
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Simplify validate_interval_range and callers
    
    * src/textprop.c (validate_interval_range):
    Remove useless code.  Fix comment to match current behavior.
    (set_text_properties, copy_text_properties): Simplify, as
    validate_interval_range has not incremented START or END for
    quite some time.
    (copy_text_properties): Assume C99.  Fix an unlikely
    integer overflow bug if WIDE_EMACS_INT.
---
 src/textprop.c | 60 ++++++++++++++++------------------------------------------
 1 file changed, 16 insertions(+), 44 deletions(-)

diff --git a/src/textprop.c b/src/textprop.c
index add14eb..8a06f0f 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -111,9 +111,6 @@ CHECK_STRING_OR_BUFFER (Lisp_Object x)
    to by BEGIN and END may be integers or markers; if the latter, they
    are coerced to integers.
 
-   When OBJECT is a string, we increment *BEGIN and *END
-   to make them origin-one.
-
    Note that buffer points don't correspond to interval indices.
    For example, point-max is 1 greater than the index of the last
    character.  This difference is handled in the caller, which uses
@@ -175,9 +172,6 @@ validate_interval_range (Lisp_Object object, Lisp_Object 
*begin,
       if (! (0 <= XFIXNUM (*begin) && XFIXNUM (*begin) <= XFIXNUM (*end)
             && XFIXNUM (*end) <= len))
        args_out_of_range (*begin, *end);
-      XSETFASTINT (*begin, XFIXNAT (*begin));
-      if (begin != end)
-       XSETFASTINT (*end, XFIXNAT (*end));
       i = string_intervals (object);
 
       if (len == 0)
@@ -1348,13 +1342,9 @@ Lisp_Object
 set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object 
properties,
                     Lisp_Object object, Lisp_Object coherent_change_p)
 {
-  register INTERVAL i;
-  Lisp_Object ostart, oend;
+  INTERVAL i;
   bool first_time = true;
 
-  ostart = start;
-  oend = end;
-
   properties = validate_plist (properties);
 
   if (NILP (object))
@@ -1382,11 +1372,6 @@ set_text_properties (Lisp_Object start, Lisp_Object end, 
Lisp_Object properties,
       if (NILP (properties))
        return Qnil;
 
-      /* Restore the original START and END values
-        because validate_interval_range increments them for strings.  */
-      start = ostart;
-      end = oend;
-
       i = validate_interval_range (object, &start, &end, hard);
       /* This can return if start == end.  */
       if (!i)
@@ -1887,45 +1872,30 @@ Lisp_Object
 copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src,
                      Lisp_Object pos, Lisp_Object dest, Lisp_Object prop)
 {
-  INTERVAL i;
-  Lisp_Object res;
-  Lisp_Object stuff;
-  Lisp_Object plist;
-  ptrdiff_t s, e, e2, p, len;
-  bool modified = false;
-
-  i = validate_interval_range (src, &start, &end, soft);
+  INTERVAL i = validate_interval_range (src, &start, &end, soft);
   if (!i)
     return Qnil;
 
   CHECK_FIXNUM_COERCE_MARKER (pos);
-  {
-    Lisp_Object dest_start, dest_end;
-
-    e = XFIXNUM (pos) + (XFIXNUM (end) - XFIXNUM (start));
-    if (MOST_POSITIVE_FIXNUM < e)
-      args_out_of_range (pos, end);
-    dest_start = pos;
-    XSETFASTINT (dest_end, e);
-    /* Apply this to a copy of pos; it will try to increment its arguments,
-       which we don't want.  */
-    validate_interval_range (dest, &dest_start, &dest_end, soft);
-  }
 
-  s = XFIXNUM (start);
-  e = XFIXNUM (end);
-  p = XFIXNUM (pos);
+  EMACS_INT dest_e = XFIXNUM (pos) + (XFIXNUM (end) - XFIXNUM (start));
+  if (MOST_POSITIVE_FIXNUM < dest_e)
+    args_out_of_range (pos, end);
+  Lisp_Object dest_end = make_fixnum (dest_e);
+  validate_interval_range (dest, &pos, &dest_end, soft);
 
-  stuff = Qnil;
+  ptrdiff_t s = XFIXNUM (start), e = XFIXNUM (end), p = XFIXNUM (pos);
+
+  Lisp_Object stuff = Qnil;
 
   while (s < e)
     {
-      e2 = i->position + LENGTH (i);
+      ptrdiff_t e2 = i->position + LENGTH (i);
       if (e2 > e)
        e2 = e;
-      len = e2 - s;
+      ptrdiff_t len = e2 - s;
 
-      plist = i->plist;
+      Lisp_Object plist = i->plist;
       if (! NILP (prop))
        while (! NILP (plist))
          {
@@ -1950,9 +1920,11 @@ copy_text_properties (Lisp_Object start, Lisp_Object 
end, Lisp_Object src,
       s = i->position;
     }
 
+  bool modified = false;
+
   while (! NILP (stuff))
     {
-      res = Fcar (stuff);
+      Lisp_Object res = Fcar (stuff);
       res = Fadd_text_properties (Fcar (res), Fcar (Fcdr (res)),
                                  Fcar (Fcdr (Fcdr (res))), dest);
       if (! NILP (res))



reply via email to

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