comparison src/intervals.c @ 52577:0f4f05ddd3df

(graft_intervals_into_buffer): Correct the main loop in the case where OVER is longer than UNDER.
author Richard M. Stallman <rms@gnu.org>
date Mon, 22 Sep 2003 15:51:19 +0000
parents 695cf19ef79e
children 32ebe48159a6
comparison
equal deleted inserted replaced
52576:a90f7b4afc00 52577:0f4f05ddd3df
1710 struct buffer *buffer; 1710 struct buffer *buffer;
1711 int inherit; 1711 int inherit;
1712 { 1712 {
1713 register INTERVAL under, over, this, prev; 1713 register INTERVAL under, over, this, prev;
1714 register INTERVAL tree; 1714 register INTERVAL tree;
1715 int over_used;
1715 1716
1716 tree = BUF_INTERVALS (buffer); 1717 tree = BUF_INTERVALS (buffer);
1717 1718
1718 /* If the new text has no properties, then with inheritance it 1719 /* If the new text has no properties, then with inheritance it
1719 becomes part of whatever interval it was inserted into. 1720 becomes part of whatever interval it was inserted into.
1812 which means it gets those properties. 1813 which means it gets those properties.
1813 The properties of under are the result of 1814 The properties of under are the result of
1814 adjust_intervals_for_insertion, so stickiness has 1815 adjust_intervals_for_insertion, so stickiness has
1815 already been taken care of. */ 1816 already been taken care of. */
1816 1817
1818 /* OVER is the interval we are copying from next.
1819 OVER_USED says how many characters' worth of OVER
1820 have already been copied into target intervals.
1821 UNDER is the next interval in the target. */
1822 over_used = 0;
1817 while (! NULL_INTERVAL_P (over)) 1823 while (! NULL_INTERVAL_P (over))
1818 { 1824 {
1825 /* If UNDER is longer than OVER, split it. */
1819 if (LENGTH (over) < LENGTH (under)) 1826 if (LENGTH (over) < LENGTH (under))
1820 { 1827 {
1821 this = split_interval_left (under, LENGTH (over)); 1828 this = split_interval_left (under, LENGTH (over));
1822 copy_properties (under, this); 1829 copy_properties (under, this);
1823 } 1830 }
1824 else 1831 else
1825 this = under; 1832 this = under;
1826 copy_properties (over, this); 1833
1834 /* THIS is now the interval to copy or merge into.
1835 OVER covers all of it. */
1827 if (inherit) 1836 if (inherit)
1828 merge_properties (over, this); 1837 merge_properties (over, this);
1829 else 1838 else
1830 copy_properties (over, this); 1839 copy_properties (over, this);
1831 over = next_interval (over); 1840
1841 /* If THIS and OVER end at the same place,
1842 advance OVER to a new source interval. */
1843 if (LENGTH (this) == LENGTH (over) - over_used)
1844 {
1845 over = next_interval (over);
1846 over_used = 0;
1847 }
1848 else
1849 /* Otherwise just record that more of OVER has been used. */
1850 over_used += LENGTH (this);
1851
1852 /* Always advance to a new target interval. */
1853 under = next_interval (this);
1832 } 1854 }
1833 1855
1834 if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) 1856 if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer)))
1835 BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); 1857 BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
1836 return; 1858 return;