aboutsummaryrefslogtreecommitdiffstats
path: root/src/intervals.c
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2011-11-18 11:00:40 -0500
committerStefan Monnier <[email protected]>2011-11-18 11:00:40 -0500
commitb50a28de8707794ff4b4b755af3173cd19004976 (patch)
treeb8d300d66b7c1046ff39e67fb332722181148f61 /src/intervals.c
parent6944dbc18a1591bc7435193685db90a6b9343914 (diff)
* src/intervals.c: Fix grafting over the whole buffer.
(graft_intervals_into_buffer): Simplify. Fixes: debbugs:10071
Diffstat (limited to 'src/intervals.c')
-rw-r--r--src/intervals.c41
1 files changed, 12 insertions, 29 deletions
diff --git a/src/intervals.c b/src/intervals.c
index a78c7f07f6..35d05d021f 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -1317,7 +1317,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
if (NULL_INTERVAL_P (tree))
return 0;
- /* Left branch */
+ /* Left branch. */
if (relative_position < LEFT_TOTAL_LENGTH (tree))
{
EMACS_INT subtract = interval_deletion_adjustment (tree->left,
@@ -1327,7 +1327,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
CHECK_TOTAL_LENGTH (tree);
return subtract;
}
- /* Right branch */
+ /* Right branch. */
else if (relative_position >= (TOTAL_LENGTH (tree)
- RIGHT_TOTAL_LENGTH (tree)))
{
@@ -1699,54 +1699,37 @@ graft_intervals_into_buffer (INTERVAL source, EMACS_INT position,
Qnil, buf, 0);
}
if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer)))
- /* Shouldn't be necessary. -stef */
+ /* Shouldn't be necessary. --Stef */
BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
return;
}
- if (NULL_INTERVAL_P (tree))
- {
- /* The inserted text constitutes the whole buffer, so
+ eassert (length == TOTAL_LENGTH (source));
+
+ if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length)
+ { /* The inserted text constitutes the whole buffer, so
simply copy over the interval structure. */
- if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source))
- {
Lisp_Object buf;
XSETBUFFER (buf, buffer);
BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf);
- BUF_INTERVALS (buffer)->position = BEG;
- BUF_INTERVALS (buffer)->up_obj = 1;
-
+ BUF_INTERVALS (buffer)->position = BUF_BEG (buffer);
+ eassert (BUF_INTERVALS (buffer)->up_obj == 1);
return;
}
-
- /* Create an interval tree in which to place a copy
+ else if (NULL_INTERVAL_P (tree))
+ { /* 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);
}
- }
- else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source))
- /* If the buffer contains only the new string, but
- there was already some interval tree there, then it may be
- some zero length intervals. Eventually, do something clever
- about inserting properly. For now, just waste the old intervals. */
- {
- BUF_INTERVALS (buffer) = reproduce_tree (source, INTERVAL_PARENT (tree));
- BUF_INTERVALS (buffer)->position = BEG;
- BUF_INTERVALS (buffer)->up_obj = 1;
- /* Explicitly free the old tree here. */
-
- return;
- }
/* Paranoia -- the text has already been added, so this buffer
should be of non-zero length. */
else if (TOTAL_LENGTH (tree) == 0)
abort ();
this = under = find_interval (tree, position);
- if (NULL_INTERVAL_P (under)) /* Paranoia */
+ if (NULL_INTERVAL_P (under)) /* Paranoia. */
abort ();
over = find_interval (source, interval_start_pos (source));