Commit 8a247f60 authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent 23e9e8ab
Pipeline #265 failed with stage
in 4 minutes and 50 seconds
......@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment