diff options
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 88 |
1 files changed, 27 insertions, 61 deletions
diff --git a/src/intervals.c b/src/intervals.c index 4de001f2ffc..88f47f58b52 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Code for doing intervals. | 1 | /* Code for doing intervals. |
| 2 | Copyright (C) 1993-1995, 1997-1998, 2001-2011 Free Software Foundation, Inc. | 2 | Copyright (C) 1993-1995, 1997-1998, 2001-2012 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -247,8 +247,7 @@ static int zero_length; | |||
| 247 | INTERVAL search_interval, found_interval; | 247 | INTERVAL search_interval, found_interval; |
| 248 | 248 | ||
| 249 | void | 249 | void |
| 250 | check_for_interval (i) | 250 | check_for_interval (INTERVAL i) |
| 251 | register INTERVAL i; | ||
| 252 | { | 251 | { |
| 253 | if (i == search_interval) | 252 | if (i == search_interval) |
| 254 | { | 253 | { |
| @@ -258,8 +257,7 @@ check_for_interval (i) | |||
| 258 | } | 257 | } |
| 259 | 258 | ||
| 260 | INTERVAL | 259 | INTERVAL |
| 261 | search_for_interval (i, tree) | 260 | search_for_interval (INTERVAL i, INTERVAL tree) |
| 262 | register INTERVAL i, tree; | ||
| 263 | { | 261 | { |
| 264 | icount = 0; | 262 | icount = 0; |
| 265 | search_interval = i; | 263 | search_interval = i; |
| @@ -269,8 +267,7 @@ search_for_interval (i, tree) | |||
| 269 | } | 267 | } |
| 270 | 268 | ||
| 271 | static void | 269 | static void |
| 272 | inc_interval_count (i) | 270 | inc_interval_count (INTERVAL i) |
| 273 | INTERVAL i; | ||
| 274 | { | 271 | { |
| 275 | icount++; | 272 | icount++; |
| 276 | if (LENGTH (i) == 0) | 273 | if (LENGTH (i) == 0) |
| @@ -280,8 +277,7 @@ inc_interval_count (i) | |||
| 280 | } | 277 | } |
| 281 | 278 | ||
| 282 | int | 279 | int |
| 283 | count_intervals (i) | 280 | count_intervals (INTERVAL i) |
| 284 | register INTERVAL i; | ||
| 285 | { | 281 | { |
| 286 | icount = 0; | 282 | icount = 0; |
| 287 | idepth = 0; | 283 | idepth = 0; |
| @@ -292,8 +288,7 @@ count_intervals (i) | |||
| 292 | } | 288 | } |
| 293 | 289 | ||
| 294 | static INTERVAL | 290 | static INTERVAL |
| 295 | root_interval (interval) | 291 | root_interval (INTERVAL interval) |
| 296 | INTERVAL interval; | ||
| 297 | { | 292 | { |
| 298 | register INTERVAL i = interval; | 293 | register INTERVAL i = interval; |
| 299 | 294 | ||
| @@ -804,9 +799,8 @@ update_interval (register INTERVAL i, EMACS_INT pos) | |||
| 804 | to the root. */ | 799 | to the root. */ |
| 805 | 800 | ||
| 806 | static INTERVAL | 801 | static INTERVAL |
| 807 | adjust_intervals_for_insertion (tree, position, length) | 802 | adjust_intervals_for_insertion (INTERVAL tree, EMACS_INT position, |
| 808 | INTERVAL tree; | 803 | EMACS_INT length) |
| 809 | EMACS_INT position, length; | ||
| 810 | { | 804 | { |
| 811 | register EMACS_INT relative_position; | 805 | register EMACS_INT relative_position; |
| 812 | register INTERVAL this; | 806 | register INTERVAL this; |
| @@ -1323,7 +1317,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, | |||
| 1323 | if (NULL_INTERVAL_P (tree)) | 1317 | if (NULL_INTERVAL_P (tree)) |
| 1324 | return 0; | 1318 | return 0; |
| 1325 | 1319 | ||
| 1326 | /* Left branch */ | 1320 | /* Left branch. */ |
| 1327 | if (relative_position < LEFT_TOTAL_LENGTH (tree)) | 1321 | if (relative_position < LEFT_TOTAL_LENGTH (tree)) |
| 1328 | { | 1322 | { |
| 1329 | EMACS_INT subtract = interval_deletion_adjustment (tree->left, | 1323 | EMACS_INT subtract = interval_deletion_adjustment (tree->left, |
| @@ -1333,7 +1327,7 @@ interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from, | |||
| 1333 | CHECK_TOTAL_LENGTH (tree); | 1327 | CHECK_TOTAL_LENGTH (tree); |
| 1334 | return subtract; | 1328 | return subtract; |
| 1335 | } | 1329 | } |
| 1336 | /* Right branch */ | 1330 | /* Right branch. */ |
| 1337 | else if (relative_position >= (TOTAL_LENGTH (tree) | 1331 | else if (relative_position >= (TOTAL_LENGTH (tree) |
| 1338 | - RIGHT_TOTAL_LENGTH (tree))) | 1332 | - RIGHT_TOTAL_LENGTH (tree))) |
| 1339 | { | 1333 | { |
| @@ -1431,9 +1425,8 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1431 | compiler that does not allow calling a static function (here, | 1425 | compiler that does not allow calling a static function (here, |
| 1432 | adjust_intervals_for_deletion) from a non-static inline function. */ | 1426 | adjust_intervals_for_deletion) from a non-static inline function. */ |
| 1433 | 1427 | ||
| 1434 | static inline void | 1428 | void |
| 1435 | static_offset_intervals (struct buffer *buffer, EMACS_INT start, | 1429 | offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length) |
| 1436 | EMACS_INT length) | ||
| 1437 | { | 1430 | { |
| 1438 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) | 1431 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) |
| 1439 | return; | 1432 | return; |
| @@ -1446,12 +1439,6 @@ static_offset_intervals (struct buffer *buffer, EMACS_INT start, | |||
| 1446 | adjust_intervals_for_deletion (buffer, start, -length); | 1439 | adjust_intervals_for_deletion (buffer, start, -length); |
| 1447 | } | 1440 | } |
| 1448 | } | 1441 | } |
| 1449 | |||
| 1450 | inline void | ||
| 1451 | offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length) | ||
| 1452 | { | ||
| 1453 | static_offset_intervals (buffer, start, length); | ||
| 1454 | } | ||
| 1455 | 1442 | ||
| 1456 | /* Merge interval I with its lexicographic successor. The resulting | 1443 | /* Merge interval I with its lexicographic successor. The resulting |
| 1457 | interval is returned, and has the properties of the original | 1444 | interval is returned, and has the properties of the original |
| @@ -1615,9 +1602,7 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent) | |||
| 1615 | interval. */ | 1602 | interval. */ |
| 1616 | 1603 | ||
| 1617 | static INTERVAL | 1604 | static INTERVAL |
| 1618 | make_new_interval (intervals, start, length) | 1605 | make_new_interval (INTERVAL intervals, EMACS_INT start, EMACS_INT length) |
| 1619 | INTERVAL intervals; | ||
| 1620 | EMACS_INT start, length; | ||
| 1621 | { | 1606 | { |
| 1622 | INTERVAL slot; | 1607 | INTERVAL slot; |
| 1623 | 1608 | ||
| @@ -1714,56 +1699,37 @@ graft_intervals_into_buffer (INTERVAL source, EMACS_INT position, | |||
| 1714 | Qnil, buf, 0); | 1699 | Qnil, buf, 0); |
| 1715 | } | 1700 | } |
| 1716 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) | 1701 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) |
| 1717 | /* Shouldn't be necessary. -stef */ | 1702 | /* Shouldn't be necessary. --Stef */ |
| 1718 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); | 1703 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); |
| 1719 | return; | 1704 | return; |
| 1720 | } | 1705 | } |
| 1721 | 1706 | ||
| 1722 | if (NULL_INTERVAL_P (tree)) | 1707 | eassert (length == TOTAL_LENGTH (source)); |
| 1723 | { | 1708 | |
| 1724 | /* The inserted text constitutes the whole buffer, so | 1709 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length) |
| 1710 | { /* The inserted text constitutes the whole buffer, so | ||
| 1725 | simply copy over the interval structure. */ | 1711 | simply copy over the interval structure. */ |
| 1726 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source)) | ||
| 1727 | { | ||
| 1728 | Lisp_Object buf; | 1712 | Lisp_Object buf; |
| 1729 | XSETBUFFER (buf, buffer); | 1713 | XSETBUFFER (buf, buffer); |
| 1730 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); | 1714 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); |
| 1731 | BUF_INTERVALS (buffer)->position = BEG; | 1715 | BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); |
| 1732 | BUF_INTERVALS (buffer)->up_obj = 1; | 1716 | eassert (BUF_INTERVALS (buffer)->up_obj == 1); |
| 1733 | |||
| 1734 | /* Explicitly free the old tree here? */ | ||
| 1735 | |||
| 1736 | return; | 1717 | return; |
| 1737 | } | 1718 | } |
| 1738 | 1719 | else if (NULL_INTERVAL_P (tree)) | |
| 1739 | /* Create an interval tree in which to place a copy | 1720 | { /* Create an interval tree in which to place a copy |
| 1740 | of the intervals of the inserted string. */ | 1721 | of the intervals of the inserted string. */ |
| 1741 | { | ||
| 1742 | Lisp_Object buf; | 1722 | Lisp_Object buf; |
| 1743 | XSETBUFFER (buf, buffer); | 1723 | XSETBUFFER (buf, buffer); |
| 1744 | tree = create_root_interval (buf); | 1724 | tree = create_root_interval (buf); |
| 1745 | } | 1725 | } |
| 1746 | } | ||
| 1747 | else if (TOTAL_LENGTH (tree) == TOTAL_LENGTH (source)) | ||
| 1748 | /* If the buffer contains only the new string, but | ||
| 1749 | there was already some interval tree there, then it may be | ||
| 1750 | some zero length intervals. Eventually, do something clever | ||
| 1751 | about inserting properly. For now, just waste the old intervals. */ | ||
| 1752 | { | ||
| 1753 | BUF_INTERVALS (buffer) = reproduce_tree (source, INTERVAL_PARENT (tree)); | ||
| 1754 | BUF_INTERVALS (buffer)->position = BEG; | ||
| 1755 | BUF_INTERVALS (buffer)->up_obj = 1; | ||
| 1756 | /* Explicitly free the old tree here. */ | ||
| 1757 | |||
| 1758 | return; | ||
| 1759 | } | ||
| 1760 | /* Paranoia -- the text has already been added, so this buffer | 1726 | /* Paranoia -- the text has already been added, so this buffer |
| 1761 | should be of non-zero length. */ | 1727 | should be of non-zero length. */ |
| 1762 | else if (TOTAL_LENGTH (tree) == 0) | 1728 | else if (TOTAL_LENGTH (tree) == 0) |
| 1763 | abort (); | 1729 | abort (); |
| 1764 | 1730 | ||
| 1765 | this = under = find_interval (tree, position); | 1731 | this = under = find_interval (tree, position); |
| 1766 | if (NULL_INTERVAL_P (under)) /* Paranoia */ | 1732 | if (NULL_INTERVAL_P (under)) /* Paranoia. */ |
| 1767 | abort (); | 1733 | abort (); |
| 1768 | over = find_interval (source, interval_start_pos (source)); | 1734 | over = find_interval (source, interval_start_pos (source)); |
| 1769 | 1735 | ||
| @@ -1894,7 +1860,7 @@ lookup_char_property (Lisp_Object plist, register Lisp_Object prop, int textprop | |||
| 1894 | /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to | 1860 | /* Set point in BUFFER "temporarily" to CHARPOS, which corresponds to |
| 1895 | byte position BYTEPOS. */ | 1861 | byte position BYTEPOS. */ |
| 1896 | 1862 | ||
| 1897 | inline void | 1863 | void |
| 1898 | temp_set_point_both (struct buffer *buffer, | 1864 | temp_set_point_both (struct buffer *buffer, |
| 1899 | EMACS_INT charpos, EMACS_INT bytepos) | 1865 | EMACS_INT charpos, EMACS_INT bytepos) |
| 1900 | { | 1866 | { |
| @@ -1914,7 +1880,7 @@ temp_set_point_both (struct buffer *buffer, | |||
| 1914 | 1880 | ||
| 1915 | /* Set point "temporarily", without checking any text properties. */ | 1881 | /* Set point "temporarily", without checking any text properties. */ |
| 1916 | 1882 | ||
| 1917 | inline void | 1883 | void |
| 1918 | temp_set_point (struct buffer *buffer, EMACS_INT charpos) | 1884 | temp_set_point (struct buffer *buffer, EMACS_INT charpos) |
| 1919 | { | 1885 | { |
| 1920 | temp_set_point_both (buffer, charpos, | 1886 | temp_set_point_both (buffer, charpos, |
| @@ -1934,7 +1900,7 @@ set_point (EMACS_INT charpos) | |||
| 1934 | current buffer, and the invisible property has a `stickiness' such that | 1900 | current buffer, and the invisible property has a `stickiness' such that |
| 1935 | inserting a character at position POS would inherit the property it, | 1901 | inserting a character at position POS would inherit the property it, |
| 1936 | return POS + ADJ, otherwise return POS. If TEST_INTANG is non-zero, | 1902 | return POS + ADJ, otherwise return POS. If TEST_INTANG is non-zero, |
| 1937 | then intangibility is required as well as invisibleness. | 1903 | then intangibility is required as well as invisibility. |
| 1938 | 1904 | ||
| 1939 | TEST_OFFS should be either 0 or -1, and ADJ should be either 1 or -1. | 1905 | TEST_OFFS should be either 0 or -1, and ADJ should be either 1 or -1. |
| 1940 | 1906 | ||
| @@ -2403,7 +2369,7 @@ copy_intervals (INTERVAL tree, EMACS_INT start, EMACS_INT length) | |||
| 2403 | 2369 | ||
| 2404 | /* Give STRING the properties of BUFFER from POSITION to LENGTH. */ | 2370 | /* Give STRING the properties of BUFFER from POSITION to LENGTH. */ |
| 2405 | 2371 | ||
| 2406 | inline void | 2372 | void |
| 2407 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, | 2373 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, |
| 2408 | EMACS_INT position, EMACS_INT length) | 2374 | EMACS_INT position, EMACS_INT length) |
| 2409 | { | 2375 | { |