Commit 77c7bcb1 authored by Dmitry Antipov's avatar Dmitry Antipov

Cleanup intervals.

* intervals.h (NULL_INTERVAL, DEFAULT_INTERVAL): Remove.
(NULL_INTERVAL_P): Likewise.  Adjust users.
(FRONT_STICKY_P, END_NONSTICKY_P, FRONT_NONSTICKY_P): Adjust
comment.  Move under #if 0.
* alloc.c, buffer.c, editfns.c, fns.c, insdel.c, intervals.c:
* print.c, syntax.c, textprop.c, xdisp.c: Adjust users.
parent 9c08a8d4
2012-08-08 Dmitry Antipov <dmantipov@yandex.ru>
Cleanup intervals.
* intervals.h (NULL_INTERVAL, DEFAULT_INTERVAL): Remove.
(NULL_INTERVAL_P): Likewise. Adjust users.
(FRONT_STICKY_P, END_NONSTICKY_P, FRONT_NONSTICKY_P): Adjust
comment. Move under #if 0.
* alloc.c, buffer.c, editfns.c, fns.c, insdel.c, intervals.c:
* print.c, syntax.c, textprop.c, xdisp.c: Adjust users.
2012-08-08 Dmitry Antipov <dmantipov@yandex.ru>
Check total length of intervals with eassert.
......
......@@ -1559,19 +1559,20 @@ mark_interval_tree (register INTERVAL tree)
/* Mark the interval tree rooted in I. */
#define MARK_INTERVAL_TREE(i) \
do { \
if (!NULL_INTERVAL_P (i) && !i->gcmarkbit) \
mark_interval_tree (i); \
#define MARK_INTERVAL_TREE(i) \
do { \
if (i && !i->gcmarkbit) \
mark_interval_tree (i); \
} while (0)
/* Unmark and rebalance interval tree rooted in I. */
#define UNMARK_BALANCE_INTERVALS(i) \
do { \
if (! NULL_INTERVAL_P (i)) \
(i) = balance_intervals (i); \
#define UNMARK_BALANCE_INTERVALS(i) \
do { \
if (i) \
(i) = balance_intervals (i); \
} while (0)
/***********************************************************************
String Allocation
***********************************************************************/
......@@ -2100,7 +2101,7 @@ sweep_strings (void)
/* String is live; unmark it and its intervals. */
UNMARK_STRING (s);
if (!NULL_INTERVAL_P (s->intervals))
if (s->intervals)
UNMARK_BALANCE_INTERVALS (s->intervals);
++total_strings;
......@@ -2502,7 +2503,7 @@ make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes)
return empty_multibyte_string;
s = allocate_string ();
s->intervals = NULL_INTERVAL;
s->intervals = NULL;
allocate_string_data (s, nchars, nbytes);
XSETSTRING (string, s);
string_chars_consed += nbytes;
......@@ -5221,7 +5222,7 @@ make_pure_string (const char *data,
}
s->size = nchars;
s->size_byte = multibyte ? nbytes : -1;
s->intervals = NULL_INTERVAL;
s->intervals = NULL;
XSETSTRING (string, s);
return string;
}
......@@ -5237,7 +5238,7 @@ make_pure_c_string (const char *data, ptrdiff_t nchars)
s->size = nchars;
s->size_byte = -1;
s->data = (unsigned char *) data;
s->intervals = NULL_INTERVAL;
s->intervals = NULL;
XSETSTRING (string, s);
return string;
}
......
......@@ -360,7 +360,7 @@ even if it is dead. The return value is never nil. */)
BUF_CHARS_MODIFF (b) = 1;
BUF_OVERLAY_MODIFF (b) = 1;
BUF_SAVE_MODIFF (b) = 1;
BUF_INTERVALS (b) = 0;
BUF_INTERVALS (b) = NULL;
BUF_UNCHANGED_MODIFIED (b) = 1;
BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
BUF_END_UNCHANGED (b) = 0;
......@@ -384,7 +384,7 @@ even if it is dead. The return value is never nil. */)
BVAR (b, zv_marker) = Qnil;
name = Fcopy_sequence (buffer_or_name);
STRING_SET_INTERVALS (name, NULL_INTERVAL);
STRING_SET_INTERVALS (name, NULL);
BVAR (b, name) = name;
BVAR (b, undo_list) = (SREF (name, 0) != ' ') ? Qnil : Qt;
......@@ -589,7 +589,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
all_buffers = b;
name = Fcopy_sequence (name);
STRING_SET_INTERVALS (name, NULL_INTERVAL);
STRING_SET_INTERVALS (name, NULL);
BVAR (b, name) = name;
reset_buffer (b);
......@@ -1688,7 +1688,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
m = next;
}
BUF_MARKERS (b) = NULL;
BUF_INTERVALS (b) = NULL_INTERVAL;
BUF_INTERVALS (b) = NULL;
/* Perhaps we should explicitly free the interval tree here... */
}
......@@ -4904,8 +4904,8 @@ init_buffer_once (void)
/* No one will share the text with these buffers, but let's play it safe. */
buffer_defaults.indirections = 0;
buffer_local_symbols.indirections = 0;
BUF_INTERVALS (&buffer_defaults) = 0;
BUF_INTERVALS (&buffer_local_symbols) = 0;
BUF_INTERVALS (&buffer_defaults) = NULL;
BUF_INTERVALS (&buffer_local_symbols) = NULL;
XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
......
......@@ -4637,7 +4637,7 @@ Transposing beyond buffer boundaries is an error. */)
/* Don't use Fset_text_properties: that can cause GC, which can
clobber objects stored in the tmp_intervals. */
tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
if (!NULL_INTERVAL_P (tmp_interval3))
if (tmp_interval3)
set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
/* First region smaller than second. */
......@@ -4696,11 +4696,11 @@ Transposing beyond buffer boundaries is an error. */)
tmp_interval2 = copy_intervals (cur_intv, start2, len2);
tmp_interval3 = validate_interval_range (buf, &startr1, &endr1, 0);
if (!NULL_INTERVAL_P (tmp_interval3))
if (tmp_interval3)
set_text_properties_1 (startr1, endr1, Qnil, buf, tmp_interval3);
tmp_interval3 = validate_interval_range (buf, &startr2, &endr2, 0);
if (!NULL_INTERVAL_P (tmp_interval3))
if (tmp_interval3)
set_text_properties_1 (startr2, endr2, Qnil, buf, tmp_interval3);
temp = SAFE_ALLOCA (len1_byte);
......@@ -4729,7 +4729,7 @@ Transposing beyond buffer boundaries is an error. */)
tmp_interval2 = copy_intervals (cur_intv, start2, len2);
tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
if (!NULL_INTERVAL_P (tmp_interval3))
if (tmp_interval3)
set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
/* holds region 2 */
......@@ -4762,7 +4762,7 @@ Transposing beyond buffer boundaries is an error. */)
tmp_interval2 = copy_intervals (cur_intv, start2, len2);
tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
if (!NULL_INTERVAL_P (tmp_interval3))
if (tmp_interval3)
set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
/* holds region 1 */
......
......@@ -3145,7 +3145,7 @@ decide_coding_unwind (Lisp_Object unwind_data)
set_buffer_internal (XBUFFER (buffer));
adjust_markers_for_delete (BEG, BEG_BYTE, Z, Z_BYTE);
adjust_overlays_for_delete (BEG, Z - BEG);
BUF_INTERVALS (current_buffer) = 0;
BUF_INTERVALS (current_buffer) = NULL;
TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
/* Now we are safe to change the buffer's multibyteness directly. */
......
......@@ -628,7 +628,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
ptrdiff_t thislen_byte = SBYTES (this);
memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
if (STRING_INTERVALS (this))
{
textprops[num_textprops].argnum = argnum;
textprops[num_textprops].from = 0;
......@@ -640,7 +640,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
/* Copy a single-byte string to a multibyte string. */
else if (STRINGP (this) && STRINGP (val))
{
if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
if (STRING_INTERVALS (this))
{
textprops[num_textprops].argnum = argnum;
textprops[num_textprops].from = 0;
......@@ -1060,7 +1060,7 @@ If you're not sure, whether to use `string-as-multibyte' or
str_as_multibyte (SDATA (new_string), nbytes,
SBYTES (string), NULL);
string = new_string;
STRING_SET_INTERVALS (string, NULL_INTERVAL);
STRING_SET_INTERVALS (string, NULL);
}
return string;
}
......
......@@ -844,10 +844,10 @@ insert_1_both (const char *string,
PT + nchars, PT_BYTE + nbytes,
before_markers);
if (BUF_INTERVALS (current_buffer) != 0)
if (BUF_INTERVALS (current_buffer))
offset_intervals (current_buffer, PT, nchars);
if (!inherit && BUF_INTERVALS (current_buffer) != 0)
if (!inherit && BUF_INTERVALS (current_buffer))
set_text_properties (make_number (PT), make_number (PT + nchars),
Qnil, Qnil, Qnil);
......@@ -1017,10 +1017,10 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes,
GPT, GPT_BYTE, 0);
if (BUF_INTERVALS (current_buffer) != 0)
if (BUF_INTERVALS (current_buffer))
{
offset_intervals (current_buffer, GPT - nchars, nchars);
graft_intervals_into_buffer (NULL_INTERVAL, GPT - nchars, nchars,
graft_intervals_into_buffer (NULL, GPT - nchars, nchars,
current_buffer, 0);
}
......@@ -1157,7 +1157,7 @@ insert_from_buffer_1 (struct buffer *buf,
PT_BYTE + outgoing_nbytes,
0);
if (BUF_INTERVALS (current_buffer) != 0)
if (BUF_INTERVALS (current_buffer))
offset_intervals (current_buffer, PT, nchars);
/* Get the intervals for the part of the string we are inserting. */
......@@ -1225,7 +1225,7 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
adjust_overlays_for_insert (from, len - nchars_del);
else if (len < nchars_del)
adjust_overlays_for_delete (from, nchars_del - len);
if (BUF_INTERVALS (current_buffer) != 0)
if (BUF_INTERVALS (current_buffer))
{
offset_intervals (current_buffer, from, len - nchars_del);
}
......@@ -1823,7 +1823,7 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
++windows_or_buffers_changed;
if (BUF_INTERVALS (current_buffer) != 0)
if (BUF_INTERVALS (current_buffer))
{
if (preserve_ptr)
{
......
This diff is collapsed.
......@@ -20,9 +20,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
INLINE_HEADER_BEGIN
#define NULL_INTERVAL ((INTERVAL)0)
#define INTERVAL_DEFAULT NULL_INTERVAL
/* Basic data type for use of intervals. */
struct interval
......@@ -63,28 +60,25 @@ struct interval
/* These are macros for dealing with the interval tree. */
#define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL)
/* True if this interval has no right child. */
#define NULL_RIGHT_CHILD(i) ((i)->right == NULL_INTERVAL)
#define NULL_RIGHT_CHILD(i) ((i)->right == NULL)
/* True if this interval has no left child. */
#define NULL_LEFT_CHILD(i) ((i)->left == NULL_INTERVAL)
#define NULL_LEFT_CHILD(i) ((i)->left == NULL)
/* True if this interval has no parent. */
#define NULL_PARENT(i) ((i)->up_obj || (i)->up.interval == 0)
/* True if this interval is the left child of some other interval. */
#define AM_LEFT_CHILD(i) (! NULL_PARENT (i) \
&& INTERVAL_PARENT (i)->left == (i))
#define AM_LEFT_CHILD(i) \
(! NULL_PARENT (i) && INTERVAL_PARENT (i)->left == (i))
/* True if this interval is the right child of some other interval. */
#define AM_RIGHT_CHILD(i) (! NULL_PARENT (i) \
&& INTERVAL_PARENT (i)->right == (i))
#define AM_RIGHT_CHILD(i) \
(! NULL_PARENT (i) && INTERVAL_PARENT (i)->right == (i))
/* True if this interval has no children. */
#define LEAF_INTERVAL_P(i) ((i)->left == NULL_INTERVAL \
&& (i)->right == NULL_INTERVAL)
#define LEAF_INTERVAL_P(i) ((i)->left == NULL && (i)->right == NULL)
/* True if this interval has no parent and is therefore the root. */
#define ROOT_INTERVAL_P(i) (NULL_PARENT (i))
......@@ -93,17 +87,16 @@ struct interval
#define ONLY_INTERVAL_P(i) (ROOT_INTERVAL_P ((i)) && LEAF_INTERVAL_P ((i)))
/* True if this interval has both left and right children. */
#define BOTH_KIDS_P(i) ((i)->left != NULL_INTERVAL \
&& (i)->right != NULL_INTERVAL)
#define BOTH_KIDS_P(i) ((i)->left != NULL && (i)->right != NULL)
/* The total size of all text represented by this interval and all its
children in the tree. This is zero if the interval is null. */
#define TOTAL_LENGTH(i) ((i) == NULL_INTERVAL ? 0 : (i)->total_length)
#define TOTAL_LENGTH(i) ((i) == NULL ? 0 : (i)->total_length)
/* The size of text represented by this interval alone. */
#define LENGTH(i) ((i) == NULL_INTERVAL ? 0 : (TOTAL_LENGTH ((i)) \
- TOTAL_LENGTH ((i)->right) \
- TOTAL_LENGTH ((i)->left)))
#define LENGTH(i) ((i) == NULL ? 0 : (TOTAL_LENGTH ((i)) \
- TOTAL_LENGTH ((i)->right) \
- TOTAL_LENGTH ((i)->left)))
/* The position of the character just past the end of I. Note that
the position cache i->position must be valid for this to work. */
......@@ -115,15 +108,14 @@ struct interval
/* The total size of the right subtree of this interval. */
#define RIGHT_TOTAL_LENGTH(i) ((i)->right ? (i)->right->total_length : 0)
/* These macros are for dealing with the interval properties. */
/* True if this is a default interval, which is the same as being null
or having no properties. */
#define DEFAULT_INTERVAL_P(i) (NULL_INTERVAL_P (i) || EQ ((i)->plist, Qnil))
#define DEFAULT_INTERVAL_P(i) (!i || EQ ((i)->plist, Qnil))
/* Test what type of parent we have. Three possibilities: another
interval, a buffer or string object, or NULL_INTERVAL. */
interval, a buffer or string object, or NULL. */
#define INTERVAL_HAS_PARENT(i) ((i)->up_obj == 0 && (i)->up.interval != 0)
#define INTERVAL_HAS_OBJECT(i) ((i)->up_obj)
......@@ -187,7 +179,7 @@ interval_copy_parent (INTERVAL d, INTERVAL s)
/* Get the parent interval, if any, otherwise a null pointer. Useful
for walking up to the root in a "for" loop; use this to get the
"next" value, and test the result to see if it's NULL_INTERVAL. */
"next" value, and test the result to see if it's NULL. */
#define INTERVAL_PARENT_OR_NULL(i) \
(INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0)
......@@ -195,8 +187,8 @@ interval_copy_parent (INTERVAL d, INTERVAL s)
#define RESET_INTERVAL(i) \
{ \
(i)->total_length = (i)->position = 0; \
(i)->left = (i)->right = NULL_INTERVAL; \
interval_set_parent (i, NULL_INTERVAL); \
(i)->left = (i)->right = NULL; \
interval_set_parent (i, NULL); \
(i)->write_protect = 0; \
(i)->visible = 0; \
(i)->front_sticky = (i)->rear_sticky = 0; \
......@@ -232,39 +224,36 @@ interval_copy_parent (INTERVAL d, INTERVAL s)
/* Is this interval visible? Replace later with cache access. */
#define INTERVAL_VISIBLE_P(i) \
(! NULL_INTERVAL_P (i) && NILP (textget ((i)->plist, Qinvisible)))
(i && NILP (textget ((i)->plist, Qinvisible)))
/* Is this interval writable? Replace later with cache access. */
#define INTERVAL_WRITABLE_P(i) \
(! NULL_INTERVAL_P (i) \
&& (NILP (textget ((i)->plist, Qread_only)) \
|| ((CONSP (Vinhibit_read_only) \
? !NILP (Fmemq (textget ((i)->plist, Qread_only), \
Vinhibit_read_only)) \
: !NILP (Vinhibit_read_only))))) \
(i && (NILP (textget ((i)->plist, Qread_only)) \
|| ((CONSP (Vinhibit_read_only) \
? !NILP (Fmemq (textget ((i)->plist, Qread_only), \
Vinhibit_read_only)) \
: !NILP (Vinhibit_read_only))))) \
/* Macros to tell whether insertions before or after this interval
should stick to it. */
/* Replace later with cache access */
/*#define FRONT_STICKY_P(i) ((i)->front_sticky != 0)
#define END_STICKY_P(i) ((i)->rear_sticky != 0)*/
/* As we now have Vtext_property_default_nonsticky, these macros are
unreliable now. Currently, they are never used. */
#define FRONT_STICKY_P(i) \
(! NULL_INTERVAL_P (i) && ! NILP (textget ((i)->plist, Qfront_sticky)))
#define END_NONSTICKY_P(i) \
(! NULL_INTERVAL_P (i) && ! NILP (textget ((i)->plist, Qrear_nonsticky)))
#define FRONT_NONSTICKY_P(i) \
(! NULL_INTERVAL_P (i) && ! EQ (Qt, textget ((i)->plist, Qfront_sticky)))
should stick to it. Now we have Vtext_property_default_nonsticky,
so these macros are unreliable now and never used. */
#if 0
#define FRONT_STICKY_P(i) \
(i && ! NILP (textget ((i)->plist, Qfront_sticky)))
#define END_NONSTICKY_P(i) \
(i && ! NILP (textget ((i)->plist, Qrear_nonsticky)))
#define FRONT_NONSTICKY_P(i) \
(i && ! EQ (Qt, textget ((i)->plist, Qfront_sticky)))
#endif
/* If PROP is the `invisible' property of a character,
this is 1 if the character should be treated as invisible,
and 2 if it is invisible but with an ellipsis. */
#define TEXT_PROP_MEANS_INVISIBLE(prop) \
#define TEXT_PROP_MEANS_INVISIBLE(prop) \
(EQ (BVAR (current_buffer, invisibility_spec), Qt) \
? !NILP (prop) \
? !NILP (prop) \
: invisible_p (prop, BVAR (current_buffer, invisibility_spec)))
/* Declared in alloc.c. */
......
......@@ -1408,7 +1408,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
if (! EQ (Vprint_charset_text_property, Qt))
obj = print_prune_string_charset (obj);
if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
if (STRING_INTERVALS (obj))
{
PRINTCHAR ('#');
PRINTCHAR ('(');
......@@ -1499,7 +1499,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
}
PRINTCHAR ('\"');
if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
if (STRING_INTERVALS (obj))
{
traverse_intervals (STRING_INTERVALS (obj),
0, print_interval, printcharfun);
......
......@@ -171,7 +171,7 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */
direction than the intervals - or in an interval. We update the
current syntax-table basing on the property of this interval, and
update the interval to start further than CHARPOS - or be
NULL_INTERVAL. We also update lim_property to be the next value of
NULL. We also update lim_property to be the next value of
charpos to call this subroutine again - or be before/after the
start/end of OBJECT. */
......@@ -192,7 +192,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
i = interval_of (charpos, object);
gl_state.backward_i = gl_state.forward_i = i;
invalidate = 0;
if (NULL_INTERVAL_P (i))
if (!i)
return;
/* interval_of updates only ->position of the return value, so
update the parents manually to speed up update_interval. */
......@@ -217,7 +217,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
/* We are guaranteed to be called with CHARPOS either in i,
or further off. */
if (NULL_INTERVAL_P (i))
if (!i)
error ("Error in syntax_table logic for to-the-end intervals");
else if (charpos < i->position) /* Move left. */
{
......@@ -287,7 +287,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
}
}
while (!NULL_INTERVAL_P (i))
while (i)
{
if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table)))
{
......@@ -313,7 +313,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
/* 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. */
+ (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0);
+ (next_interval (i) ? 0 : 1);
gl_state.forward_i = i;
}
else
......@@ -326,7 +326,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init,
cnt++;
i = count > 0 ? next_interval (i) : previous_interval (i);
}
eassert (NULL_INTERVAL_P (i)); /* This property goes to the end. */
eassert (i == NULL); /* This property goes to the end. */
if (count > 0)
gl_state.e_property = gl_state.stop;
else
......
This diff is collapsed.
......@@ -3321,7 +3321,7 @@ compute_stop_pos (struct it *it)
interval if there isn't such an interval. */
position = make_number (charpos);
iv = validate_interval_range (object, &position, &position, 0);
if (!NULL_INTERVAL_P (iv))
if (iv)
{
Lisp_Object values_here[LAST_PROP_IDX];
struct props *p;
......@@ -3333,7 +3333,7 @@ compute_stop_pos (struct it *it)
/* Look for an interval following iv that has different
properties. */
for (next_iv = next_interval (iv);
(!NULL_INTERVAL_P (next_iv)
(next_iv
&& (NILP (limit)
|| XFASTINT (limit) > next_iv->position));
next_iv = next_interval (next_iv))
......@@ -3351,7 +3351,7 @@ compute_stop_pos (struct it *it)
break;
}
if (!NULL_INTERVAL_P (next_iv))
if (next_iv)
{
if (INTEGERP (limit)
&& next_iv->position >= XFASTINT (limit))
......
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