aboutsummaryrefslogtreecommitdiffstats
path: root/src/intervals.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-08-08 16:12:40 +0400
committerDmitry Antipov2012-08-08 16:12:40 +0400
commit8707c1e56ca83a0a34785e451dcef428c60242fe (patch)
treef404532e675b2870620faafa8d94dacf618c1a22 /src/intervals.c
parentad8c997f72c95b7351eab4c8ea2ac8c667545e6f (diff)
downloademacs-8707c1e56ca83a0a34785e451dcef428c60242fe.tar.gz
emacs-8707c1e56ca83a0a34785e451dcef428c60242fe.zip
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.
Diffstat (limited to 'src/intervals.c')
-rw-r--r--src/intervals.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/src/intervals.c b/src/intervals.c
index 64e54eb7b43..e9c3929670e 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -77,7 +77,7 @@ create_root_interval (Lisp_Object parent)
77 new->total_length = (BUF_Z (XBUFFER (parent)) 77 new->total_length = (BUF_Z (XBUFFER (parent))
78 - BUF_BEG (XBUFFER (parent))); 78 - BUF_BEG (XBUFFER (parent)));
79 eassert (0 <= TOTAL_LENGTH (new)); 79 eassert (0 <= TOTAL_LENGTH (new));
80 BUF_INTERVALS (XBUFFER (parent)) = new; 80 buffer_set_intervals (XBUFFER (parent), new);
81 new->position = BEG; 81 new->position = BEG;
82 } 82 }
83 else if (STRINGP (parent)) 83 else if (STRINGP (parent))
@@ -453,7 +453,7 @@ balance_possible_root_interval (register INTERVAL interval)
453 if (have_parent) 453 if (have_parent)
454 { 454 {
455 if (BUFFERP (parent)) 455 if (BUFFERP (parent))
456 BUF_INTERVALS (XBUFFER (parent)) = interval; 456 buffer_set_intervals (XBUFFER (parent), interval);
457 else if (STRINGP (parent)) 457 else if (STRINGP (parent))
458 string_set_intervals (parent, interval); 458 string_set_intervals (parent, interval);
459 } 459 }
@@ -483,6 +483,19 @@ balance_intervals (INTERVAL tree)
483 return tree ? balance_intervals_internal (tree) : NULL; 483 return tree ? balance_intervals_internal (tree) : NULL;
484} 484}
485 485
486/* Rebalance text properties of B. */
487
488static void
489buffer_balance_intervals (struct buffer *b)
490{
491 INTERVAL i;
492
493 eassert (b != NULL);
494 i = buffer_get_intervals (b);
495 if (i)
496 buffer_set_intervals (b, balance_an_interval (i));
497}
498
486/* Split INTERVAL into two pieces, starting the second piece at 499/* Split INTERVAL into two pieces, starting the second piece at
487 character position OFFSET (counting from 0), relative to INTERVAL. 500 character position OFFSET (counting from 0), relative to INTERVAL.
488 INTERVAL becomes the left-hand piece, and the right-hand piece 501 INTERVAL becomes the left-hand piece, and the right-hand piece
@@ -1204,7 +1217,7 @@ delete_interval (register INTERVAL i)
1204 interval_set_object (parent, owner); 1217 interval_set_object (parent, owner);
1205 1218
1206 if (BUFFERP (owner)) 1219 if (BUFFERP (owner))
1207 BUF_INTERVALS (XBUFFER (owner)) = parent; 1220 buffer_set_intervals (XBUFFER (owner), parent);
1208 else if (STRINGP (owner)) 1221 else if (STRINGP (owner))
1209 string_set_intervals (owner, parent); 1222 string_set_intervals (owner, parent);
1210 else 1223 else
@@ -1306,7 +1319,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1306 ptrdiff_t start, ptrdiff_t length) 1319 ptrdiff_t start, ptrdiff_t length)
1307{ 1320{
1308 register ptrdiff_t left_to_delete = length; 1321 register ptrdiff_t left_to_delete = length;
1309 register INTERVAL tree = BUF_INTERVALS (buffer); 1322 register INTERVAL tree = buffer_get_intervals (buffer);
1310 Lisp_Object parent; 1323 Lisp_Object parent;
1311 ptrdiff_t offset; 1324 ptrdiff_t offset;
1312 1325
@@ -1321,7 +1334,7 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1321 1334
1322 if (length == TOTAL_LENGTH (tree)) 1335 if (length == TOTAL_LENGTH (tree))
1323 { 1336 {
1324 BUF_INTERVALS (buffer) = NULL; 1337 buffer_set_intervals (buffer, NULL);
1325 return; 1338 return;
1326 } 1339 }
1327 1340
@@ -1338,10 +1351,10 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1338 { 1351 {
1339 left_to_delete -= interval_deletion_adjustment (tree, start - offset, 1352 left_to_delete -= interval_deletion_adjustment (tree, start - offset,
1340 left_to_delete); 1353 left_to_delete);
1341 tree = BUF_INTERVALS (buffer); 1354 tree = buffer_get_intervals (buffer);
1342 if (left_to_delete == tree->total_length) 1355 if (left_to_delete == tree->total_length)
1343 { 1356 {
1344 BUF_INTERVALS (buffer) = NULL; 1357 buffer_set_intervals (buffer, NULL);
1345 return; 1358 return;
1346 } 1359 }
1347 } 1360 }
@@ -1359,11 +1372,12 @@ adjust_intervals_for_deletion (struct buffer *buffer,
1359void 1372void
1360offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) 1373offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length)
1361{ 1374{
1362 if (!BUF_INTERVALS (buffer) || length == 0) 1375 if (!buffer_get_intervals (buffer) || length == 0)
1363 return; 1376 return;
1364 1377
1365 if (length > 0) 1378 if (length > 0)
1366 adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length); 1379 adjust_intervals_for_insertion (buffer_get_intervals (buffer),
1380 start, length);
1367 else 1381 else
1368 { 1382 {
1369 IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();) 1383 IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();)
@@ -1570,7 +1584,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
1570 register INTERVAL tree; 1584 register INTERVAL tree;
1571 ptrdiff_t over_used; 1585 ptrdiff_t over_used;
1572 1586
1573 tree = BUF_INTERVALS (buffer); 1587 tree = buffer_get_intervals (buffer);
1574 1588
1575 /* If the new text has no properties, then with inheritance it 1589 /* If the new text has no properties, then with inheritance it
1576 becomes part of whatever interval it was inserted into. 1590 becomes part of whatever interval it was inserted into.
@@ -1586,31 +1600,34 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
1586 make_number (position + length), 1600 make_number (position + length),
1587 Qnil, buf, 0); 1601 Qnil, buf, 0);
1588 } 1602 }
1589 if (BUF_INTERVALS (buffer)) 1603 /* Shouldn't be necessary. --Stef */
1590 /* Shouldn't be necessary. --Stef */ 1604 buffer_balance_intervals (buffer);
1591 BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
1592 return; 1605 return;
1593 } 1606 }
1594 1607
1595 eassert (length == TOTAL_LENGTH (source)); 1608 eassert (length == TOTAL_LENGTH (source));
1596 1609
1597 if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length) 1610 if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length)
1598 { /* The inserted text constitutes the whole buffer, so 1611 {
1612 /* The inserted text constitutes the whole buffer, so
1599 simply copy over the interval structure. */ 1613 simply copy over the interval structure. */
1600 Lisp_Object buf; 1614 Lisp_Object buf;
1601 XSETBUFFER (buf, buffer); 1615
1602 BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); 1616 XSETBUFFER (buf, buffer);
1603 BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); 1617 buffer_set_intervals (buffer, reproduce_tree_obj (source, buf));
1604 eassert (BUF_INTERVALS (buffer)->up_obj == 1); 1618 buffer_get_intervals (buffer)->position = BUF_BEG (buffer);
1605 return; 1619 eassert (buffer_get_intervals (buffer)->up_obj == 1);
1606 } 1620 return;
1621 }
1607 else if (!tree) 1622 else if (!tree)
1608 { /* Create an interval tree in which to place a copy 1623 {
1624 /* Create an interval tree in which to place a copy
1609 of the intervals of the inserted string. */ 1625 of the intervals of the inserted string. */
1610 Lisp_Object buf; 1626 Lisp_Object buf;
1627
1611 XSETBUFFER (buf, buffer); 1628 XSETBUFFER (buf, buffer);
1612 tree = create_root_interval (buf); 1629 tree = create_root_interval (buf);
1613 } 1630 }
1614 /* Paranoia -- the text has already been added, so 1631 /* Paranoia -- the text has already been added, so
1615 this buffer should be of non-zero length. */ 1632 this buffer should be of non-zero length. */
1616 eassert (TOTAL_LENGTH (tree) > 0); 1633 eassert (TOTAL_LENGTH (tree) > 0);
@@ -1691,9 +1708,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position,
1691 under = next_interval (this); 1708 under = next_interval (this);
1692 } 1709 }
1693 1710
1694 if (BUF_INTERVALS (buffer)) 1711 buffer_balance_intervals (buffer);
1695 BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
1696 return;
1697} 1712}
1698 1713
1699/* Get the value of property PROP from PLIST, 1714/* Get the value of property PROP from PLIST,
@@ -1860,7 +1875,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
1860 1875
1861 /* If we have no text properties and overlays, 1876 /* If we have no text properties and overlays,
1862 then we can do it quickly. */ 1877 then we can do it quickly. */
1863 if (!BUF_INTERVALS (current_buffer) && ! have_overlays) 1878 if (!buffer_get_intervals (current_buffer) && ! have_overlays)
1864 { 1879 {
1865 temp_set_point_both (current_buffer, charpos, bytepos); 1880 temp_set_point_both (current_buffer, charpos, bytepos);
1866 return; 1881 return;
@@ -1869,7 +1884,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
1869 /* Set TO to the interval containing the char after CHARPOS, 1884 /* Set TO to the interval containing the char after CHARPOS,
1870 and TOPREV to the interval containing the char before CHARPOS. 1885 and TOPREV to the interval containing the char before CHARPOS.
1871 Either one may be null. They may be equal. */ 1886 Either one may be null. They may be equal. */
1872 to = find_interval (BUF_INTERVALS (current_buffer), charpos); 1887 to = find_interval (buffer_get_intervals (current_buffer), charpos);
1873 if (charpos == BEGV) 1888 if (charpos == BEGV)
1874 toprev = 0; 1889 toprev = 0;
1875 else if (to && to->position == charpos) 1890 else if (to && to->position == charpos)
@@ -1883,7 +1898,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
1883 and FROMPREV to the interval containing the char before PT. 1898 and FROMPREV to the interval containing the char before PT.
1884 Either one may be null. They may be equal. */ 1899 Either one may be null. They may be equal. */
1885 /* We could cache this and save time. */ 1900 /* We could cache this and save time. */
1886 from = find_interval (BUF_INTERVALS (current_buffer), buffer_point); 1901 from = find_interval (buffer_get_intervals (current_buffer), buffer_point);
1887 if (buffer_point == BEGV) 1902 if (buffer_point == BEGV)
1888 fromprev = 0; 1903 fromprev = 0;
1889 else if (from && from->position == PT) 1904 else if (from && from->position == PT)
@@ -1989,7 +2004,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos)
1989 /* Set TO to the interval containing the char after CHARPOS, 2004 /* Set TO to the interval containing the char after CHARPOS,
1990 and TOPREV to the interval containing the char before CHARPOS. 2005 and TOPREV to the interval containing the char before CHARPOS.
1991 Either one may be null. They may be equal. */ 2006 Either one may be null. They may be equal. */
1992 to = find_interval (BUF_INTERVALS (current_buffer), charpos); 2007 to = find_interval (buffer_get_intervals (current_buffer), charpos);
1993 if (charpos == BEGV) 2008 if (charpos == BEGV)
1994 toprev = 0; 2009 toprev = 0;
1995 else if (to && to->position == charpos) 2010 else if (to && to->position == charpos)
@@ -2122,9 +2137,9 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val,
2122 INTERVAL i, prev, next; 2137 INTERVAL i, prev, next;
2123 2138
2124 if (NILP (object)) 2139 if (NILP (object))
2125 i = find_interval (BUF_INTERVALS (current_buffer), pos); 2140 i = find_interval (buffer_get_intervals (current_buffer), pos);
2126 else if (BUFFERP (object)) 2141 else if (BUFFERP (object))
2127 i = find_interval (BUF_INTERVALS (XBUFFER (object)), pos); 2142 i = find_interval (buffer_get_intervals (XBUFFER (object)), pos);
2128 else if (STRINGP (object)) 2143 else if (STRINGP (object))
2129 i = find_interval (string_get_intervals (object), pos); 2144 i = find_interval (string_get_intervals (object), pos);
2130 else 2145 else
@@ -2253,7 +2268,7 @@ void
2253copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, 2268copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
2254 ptrdiff_t position, ptrdiff_t length) 2269 ptrdiff_t position, ptrdiff_t length)
2255{ 2270{
2256 INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer), 2271 INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer),
2257 position, length); 2272 position, length);
2258 if (!interval_copy) 2273 if (!interval_copy)
2259 return; 2274 return;
@@ -2418,7 +2433,8 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
2418void 2433void
2419set_intervals_multibyte (int multi_flag) 2434set_intervals_multibyte (int multi_flag)
2420{ 2435{
2421 if (BUF_INTERVALS (current_buffer)) 2436 INTERVAL i = buffer_get_intervals (current_buffer);
2422 set_intervals_multibyte_1 (BUF_INTERVALS (current_buffer), multi_flag, 2437
2423 BEG, BEG_BYTE, Z, Z_BYTE); 2438 if (i)
2439 set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE);
2424} 2440}