Commit 8707c1e5 authored by Dmitry Antipov's avatar Dmitry Antipov

Inline functions to examine and change buffer intervals.

* alloc.c (mark_interval_tree): Remove.
(MARK_INTERVAL_TREE): Simplify.
(UNMARK_BALANCE_INTERVALS): Remove.  Adjust users.
* intervals.c (buffer_balance_intervals): New function.
(graft_intervals_into_buffer): Adjust indentation.
(set_intervals_multibyte): Simplify.
* buffer.h (BUF_INTERVALS): Remove.
(buffer_get_intervals, buffer_set_intervals): New function.
* alloc.c, buffer.c, editfns.c, fileio.c, indent.c, insdel.c:
* intervals.c, textprop.c: Adjust users.
parent ad8c997f
2012-08-08 Dmitry Antipov <dmantipov@yandex.ru>
Inline functions to examine and change buffer intervals.
* alloc.c (mark_interval_tree): Remove.
(MARK_INTERVAL_TREE): Simplify.
(UNMARK_BALANCE_INTERVALS): Remove. Adjust users.
* intervals.c (buffer_balance_intervals): New function.
(graft_intervals_into_buffer): Adjust indentation.
(set_intervals_multibyte): Simplify.
* buffer.h (BUF_INTERVALS): Remove.
(buffer_get_intervals, buffer_set_intervals): New function.
* alloc.c, buffer.c, editfns.c, fileio.c, indent.c, insdel.c:
* intervals.c, textprop.c: Adjust users.
2012-08-08 Dmitry Antipov <dmantipov@yandex.ru>
Inline functions to examine and change string intervals.
......
......@@ -1542,35 +1542,12 @@ mark_interval (register INTERVAL i, Lisp_Object dummy)
mark_object (i->plist);
}
/* Mark the interval tree rooted in TREE. Don't call this directly;
use the macro MARK_INTERVAL_TREE instead. */
static void
mark_interval_tree (register INTERVAL tree)
{
/* No need to test if this tree has been marked already; this
function is always called through the MARK_INTERVAL_TREE macro,
which takes care of that. */
traverse_intervals_noorder (tree, mark_interval, Qnil);
}
/* Mark the interval tree rooted in 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 (i) \
(i) = balance_intervals (i); \
#define MARK_INTERVAL_TREE(i) \
do { \
if (i && !i->gcmarkbit) \
traverse_intervals_noorder (i, mark_interval, Qnil); \
} while (0)
/***********************************************************************
......@@ -2101,8 +2078,8 @@ sweep_strings (void)
/* String is live; unmark it and its intervals. */
UNMARK_STRING (s);
if (s->intervals)
UNMARK_BALANCE_INTERVALS (s->intervals);
/* Do not use string_(set|get)_intervals here. */
s->intervals = balance_intervals (s->intervals);
++total_strings;
total_string_bytes += STRING_BYTES (s);
......@@ -5848,7 +5825,7 @@ mark_buffer (struct buffer *buffer)
/* ...but there are some buffer-specific things. */
MARK_INTERVAL_TREE (BUF_INTERVALS (buffer));
MARK_INTERVAL_TREE (buffer_get_intervals (buffer));
/* For now, we just don't mark the undo_list. It's done later in
a special way just before the sweep phase, and after stripping
......@@ -6587,7 +6564,8 @@ gc_sweep (void)
else
{
VECTOR_UNMARK (buffer);
UNMARK_BALANCE_INTERVALS (BUF_INTERVALS (buffer));
/* Do not use buffer_(set|get)_intervals here. */
buffer->text->intervals = balance_intervals (buffer->text->intervals);
total_buffers++;
prev = buffer, buffer = buffer->header.next.buffer;
}
......
......@@ -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) = NULL;
buffer_set_intervals (b, NULL);
BUF_UNCHANGED_MODIFIED (b) = 1;
BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
BUF_END_UNCHANGED (b) = 0;
......@@ -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;
buffer_set_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) = NULL;
BUF_INTERVALS (&buffer_local_symbols) = NULL;
buffer_set_intervals (&buffer_defaults, NULL);
buffer_set_intervals (&buffer_local_symbols, NULL);
XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
......
......@@ -193,9 +193,6 @@ INLINE_HEADER_BEGIN
/* FIXME: should we move this into ->text->auto_save_modiff? */
#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
/* Interval tree of buffer. */
#define BUF_INTERVALS(buf) ((buf)->text->intervals)
/* Marker chain of buffer. */
#define BUF_MARKERS(buf) ((buf)->text->markers)
......@@ -951,7 +948,25 @@ extern void mmap_set_vars (int);
extern Lisp_Object Qbefore_change_functions;
extern Lisp_Object Qafter_change_functions;
extern Lisp_Object Qfirst_change_hook;
/* Get text properties of B. */
BUFFER_INLINE INTERVAL
buffer_get_intervals (struct buffer *b)
{
eassert (b->text != NULL);
return b->text->intervals;
}
/* Set text properties of B to I. */
BUFFER_INLINE void
buffer_set_intervals (struct buffer *b, INTERVAL i)
{
eassert (b->text != NULL);
b->text->intervals = i;
}
/* Return character code of multi-byte form at byte position POS. If POS
doesn't point the head of valid multi-byte form, only the byte at
POS is returned. No range checking.
......
......@@ -4527,7 +4527,7 @@ Transposing beyond buffer boundaries is an error. */)
Lisp_Object buf;
XSETBUFFER (buf, current_buffer);
cur_intv = BUF_INTERVALS (current_buffer);
cur_intv = buffer_get_intervals (current_buffer);
validate_region (&startr1, &endr1);
validate_region (&startr2, &endr2);
......
......@@ -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) = NULL;
buffer_set_intervals (current_buffer, NULL);
TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
/* Now we are safe to change the buffer's multibyteness directly. */
......
......@@ -336,7 +336,7 @@ current_column (void)
/* If the buffer has overlays, text properties,
or multibyte characters, use a more general algorithm. */
if (BUF_INTERVALS (current_buffer)
if (buffer_get_intervals (current_buffer)
|| current_buffer->overlays_before
|| current_buffer->overlays_after
|| Z != Z_BYTE)
......
......@@ -844,10 +844,10 @@ insert_1_both (const char *string,
PT + nchars, PT_BYTE + nbytes,
before_markers);
if (BUF_INTERVALS (current_buffer))
if (buffer_get_intervals (current_buffer))
offset_intervals (current_buffer, PT, nchars);
if (!inherit && BUF_INTERVALS (current_buffer))
if (!inherit && buffer_get_intervals (current_buffer))
set_text_properties (make_number (PT), make_number (PT + nchars),
Qnil, Qnil, Qnil);
......@@ -1017,7 +1017,7 @@ 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))
if (buffer_get_intervals (current_buffer))
{
offset_intervals (current_buffer, GPT - nchars, nchars);
graft_intervals_into_buffer (NULL, GPT - nchars, nchars,
......@@ -1157,11 +1157,11 @@ insert_from_buffer_1 (struct buffer *buf,
PT_BYTE + outgoing_nbytes,
0);
if (BUF_INTERVALS (current_buffer))
if (buffer_get_intervals (current_buffer))
offset_intervals (current_buffer, PT, nchars);
/* Get the intervals for the part of the string we are inserting. */
intervals = BUF_INTERVALS (buf);
intervals = buffer_get_intervals (buf);
if (nchars < BUF_Z (buf) - BUF_BEG (buf))
{
if (buf == current_buffer && PT <= from)
......@@ -1225,10 +1225,9 @@ 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))
{
offset_intervals (current_buffer, from, len - nchars_del);
}
if (buffer_get_intervals (current_buffer))
offset_intervals (current_buffer, from, len - nchars_del);
if (from < PT)
adjust_point (len - nchars_del, len_byte - nbytes_del);
......@@ -1823,7 +1822,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))
if (buffer_get_intervals (current_buffer))
{
if (preserve_ptr)
{
......
......@@ -77,7 +77,7 @@ create_root_interval (Lisp_Object parent)
new->total_length = (BUF_Z (XBUFFER (parent))
- BUF_BEG (XBUFFER (parent)));
eassert (0 <= TOTAL_LENGTH (new));
BUF_INTERVALS (XBUFFER (parent)) = new;
buffer_set_intervals (XBUFFER (parent), new);
new->position = BEG;
}
else if (STRINGP (parent))
......@@ -453,7 +453,7 @@ balance_possible_root_interval (register INTERVAL interval)
if (have_parent)
{
if (BUFFERP (parent))
BUF_INTERVALS (XBUFFER (parent)) = interval;
buffer_set_intervals (XBUFFER (parent), interval);
else if (STRINGP (parent))
string_set_intervals (parent, interval);
}
......@@ -483,6 +483,19 @@ balance_intervals (INTERVAL tree)
return tree ? balance_intervals_internal (tree) : NULL;
}
/* Rebalance text properties of B. */
static void
buffer_balance_intervals (struct buffer *b)
{
INTERVAL i;
eassert (b != NULL);
i = buffer_get_intervals (b);
if (i)
buffer_set_intervals (b, balance_an_interval (i));
}
/* Split INTERVAL into two pieces, starting the second piece at
character position OFFSET (counting from 0), relative to INTERVAL.
INTERVAL becomes the left-hand piece, and the right-hand piece
......@@ -1204,7 +1217,7 @@ delete_interval (register INTERVAL i)
interval_set_object (parent, owner);
if (BUFFERP (owner))
BUF_INTERVALS (XBUFFER (owner)) = parent;
buffer_set_intervals (XBUFFER (owner), parent);
else if (STRINGP (owner))
string_set_intervals (owner, parent);
else
......@@ -1306,7 +1319,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
ptrdiff_t start, ptrdiff_t length)
{
register ptrdiff_t left_to_delete = length;
register INTERVAL tree = BUF_INTERVALS (buffer);
register INTERVAL tree = buffer_get_intervals (buffer);
Lisp_Object parent;
ptrdiff_t offset;
......@@ -1321,7 +1334,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
if (length == TOTAL_LENGTH (tree))
{
BUF_INTERVALS (buffer) = NULL;
buffer_set_intervals (buffer, NULL);
return;
}
......@@ -1338,10 +1351,10 @@ adjust_intervals_for_deletion (struct buffer *buffer,
{
left_to_delete -= interval_deletion_adjustment (tree, start - offset,
left_to_delete);
tree = BUF_INTERVALS (buffer);
tree = buffer_get_intervals (buffer);
if (left_to_delete == tree->total_length)
{
BUF_INTERVALS (buffer) = NULL;
buffer_set_intervals (buffer, NULL);
return;
}
}
......@@ -1359,11 +1372,12 @@ adjust_intervals_for_deletion (struct buffer *buffer,
void
offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length)
{
if (!BUF_INTERVALS (buffer) || length == 0)
if (!buffer_get_intervals (buffer) || length == 0)
return;
if (length > 0)
adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length);
adjust_intervals_for_insertion (buffer_get_intervals (buffer),
start, length);
else
{
IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();)
......@@ -1570,7 +1584,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
register INTERVAL tree;
ptrdiff_t over_used;
tree = BUF_INTERVALS (buffer);
tree = buffer_get_intervals (buffer);
/* If the new text has no properties, then with inheritance it
becomes part of whatever interval it was inserted into.
......@@ -1586,31 +1600,34 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
make_number (position + length),
Qnil, buf, 0);
}
if (BUF_INTERVALS (buffer))
/* Shouldn't be necessary. --Stef */
BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
/* Shouldn't be necessary. --Stef */
buffer_balance_intervals (buffer);
return;
}
eassert (length == TOTAL_LENGTH (source));
if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length)
{ /* The inserted text constitutes the whole buffer, so
{
/* The inserted text constitutes the whole buffer, so
simply copy over the interval structure. */
Lisp_Object buf;
XSETBUFFER (buf, buffer);
BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf);
BUF_INTERVALS (buffer)->position = BUF_BEG (buffer);
eassert (BUF_INTERVALS (buffer)->up_obj == 1);
return;
}
Lisp_Object buf;
XSETBUFFER (buf, buffer);
buffer_set_intervals (buffer, reproduce_tree_obj (source, buf));
buffer_get_intervals (buffer)->position = BUF_BEG (buffer);
eassert (buffer_get_intervals (buffer)->up_obj == 1);
return;
}
else if (!tree)
{ /* Create an interval tree in which to place a copy
{
/* Create an interval tree in which to place a copy
of the intervals of the inserted string. */
Lisp_Object buf;
XSETBUFFER (buf, buffer);
tree = create_root_interval (buf);
}
}
/* Paranoia -- the text has already been added, so
this buffer should be of non-zero length. */
eassert (TOTAL_LENGTH (tree) > 0);
......@@ -1691,9 +1708,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
under = next_interval (this);
}
if (BUF_INTERVALS (buffer))
BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
return;
buffer_balance_intervals (buffer);
}
/* Get the value of property PROP from PLIST,
......@@ -1860,7 +1875,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
/* If we have no text properties and overlays,
then we can do it quickly. */
if (!BUF_INTERVALS (current_buffer) && ! have_overlays)
if (!buffer_get_intervals (current_buffer) && ! have_overlays)
{
temp_set_point_both (current_buffer, charpos, bytepos);
return;
......@@ -1869,7 +1884,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
/* Set TO to the interval containing the char after CHARPOS,
and TOPREV to the interval containing the char before CHARPOS.
Either one may be null. They may be equal. */
to = find_interval (BUF_INTERVALS (current_buffer), charpos);
to = find_interval (buffer_get_intervals (current_buffer), charpos);
if (charpos == BEGV)
toprev = 0;
else if (to && to->position == charpos)
......@@ -1883,7 +1898,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
and FROMPREV to the interval containing the char before PT.
Either one may be null. They may be equal. */
/* We could cache this and save time. */
from = find_interval (BUF_INTERVALS (current_buffer), buffer_point);
from = find_interval (buffer_get_intervals (current_buffer), buffer_point);
if (buffer_point == BEGV)
fromprev = 0;
else if (from && from->position == PT)
......@@ -1989,7 +2004,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
/* Set TO to the interval containing the char after CHARPOS,
and TOPREV to the interval containing the char before CHARPOS.
Either one may be null. They may be equal. */
to = find_interval (BUF_INTERVALS (current_buffer), charpos);
to = find_interval (buffer_get_intervals (current_buffer), charpos);
if (charpos == BEGV)
toprev = 0;
else if (to && to->position == charpos)
......@@ -2122,9 +2137,9 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val,
INTERVAL i, prev, next;
if (NILP (object))
i = find_interval (BUF_INTERVALS (current_buffer), pos);
i = find_interval (buffer_get_intervals (current_buffer), pos);
else if (BUFFERP (object))
i = find_interval (BUF_INTERVALS (XBUFFER (object)), pos);
i = find_interval (buffer_get_intervals (XBUFFER (object)), pos);
else if (STRINGP (object))
i = find_interval (string_get_intervals (object), pos);
else
......@@ -2253,7 +2268,7 @@ void
copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
ptrdiff_t position, ptrdiff_t length)
{
INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer),
INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer),
position, length);
if (!interval_copy)
return;
......@@ -2418,7 +2433,8 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
void
set_intervals_multibyte (int multi_flag)
{
if (BUF_INTERVALS (current_buffer))
set_intervals_multibyte_1 (BUF_INTERVALS (current_buffer), multi_flag,
BEG, BEG_BYTE, Z, Z_BYTE);
INTERVAL i = buffer_get_intervals (current_buffer);
if (i)
set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE);
}
......@@ -143,7 +143,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, Lisp_Object *en
if (!(BUF_BEGV (b) <= XINT (*begin) && XINT (*begin) <= XINT (*end)
&& XINT (*end) <= BUF_ZV (b)))
args_out_of_range (*begin, *end);
i = BUF_INTERVALS (b);
i = buffer_get_intervals (b);
/* If there's no text, there are no properties. */
if (BUF_BEGV (b) == BUF_ZV (b))
......@@ -510,7 +510,7 @@ interval_of (ptrdiff_t position, Lisp_Object object)
beg = BUF_BEGV (b);
end = BUF_ZV (b);
i = BUF_INTERVALS (b);
i = buffer_get_intervals (b);
}
else
{
......@@ -1338,8 +1338,8 @@ set_text_properties_1 (Lisp_Object start, Lisp_Object end, Lisp_Object propertie
else
return;
if (i == 0)
i = find_interval (BUF_INTERVALS (XBUFFER (buffer)), s);
if (i == NULL)
i = find_interval (buffer_get_intervals (XBUFFER (buffer)), s);
if (i->position != s)
{
......@@ -1993,7 +1993,7 @@ void
verify_interval_modification (struct buffer *buf,
ptrdiff_t start, ptrdiff_t end)
{
register INTERVAL intervals = BUF_INTERVALS (buf);
register INTERVAL intervals = buffer_get_intervals (buf);
register INTERVAL i;
Lisp_Object hooks;
register Lisp_Object prev_mod_hooks;
......
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