diff options
| author | Joakim Verona | 2012-08-15 21:49:40 +0200 |
|---|---|---|
| committer | Joakim Verona | 2012-08-15 21:49:40 +0200 |
| commit | b648c26ec642a1dc58c0bd7e59d6011b964dbe37 (patch) | |
| tree | f0f3b38ffa9054702f475fc53622e28da14f97b1 /src/intervals.c | |
| parent | c8b0fc1999006af5a4317b44068fac13d9592143 (diff) | |
| parent | 94c9ece10275f8ca9323c38f93607f1046035c79 (diff) | |
| download | emacs-b648c26ec642a1dc58c0bd7e59d6011b964dbe37.tar.gz emacs-b648c26ec642a1dc58c0bd7e59d6011b964dbe37.zip | |
upstream
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 368 |
1 files changed, 187 insertions, 181 deletions
diff --git a/src/intervals.c b/src/intervals.c index cd1254b5e46..09949bbbd45 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -38,6 +38,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | #include <config.h> | 40 | #include <config.h> |
| 41 | |||
| 42 | #define INTERVALS_INLINE EXTERN_INLINE | ||
| 43 | |||
| 41 | #include <setjmp.h> | 44 | #include <setjmp.h> |
| 42 | #include <intprops.h> | 45 | #include <intprops.h> |
| 43 | #include "lisp.h" | 46 | #include "lisp.h" |
| @@ -76,19 +79,19 @@ create_root_interval (Lisp_Object parent) | |||
| 76 | { | 79 | { |
| 77 | new->total_length = (BUF_Z (XBUFFER (parent)) | 80 | new->total_length = (BUF_Z (XBUFFER (parent)) |
| 78 | - BUF_BEG (XBUFFER (parent))); | 81 | - BUF_BEG (XBUFFER (parent))); |
| 79 | CHECK_TOTAL_LENGTH (new); | 82 | eassert (0 <= TOTAL_LENGTH (new)); |
| 80 | BUF_INTERVALS (XBUFFER (parent)) = new; | 83 | buffer_set_intervals (XBUFFER (parent), new); |
| 81 | new->position = BEG; | 84 | new->position = BEG; |
| 82 | } | 85 | } |
| 83 | else if (STRINGP (parent)) | 86 | else if (STRINGP (parent)) |
| 84 | { | 87 | { |
| 85 | new->total_length = SCHARS (parent); | 88 | new->total_length = SCHARS (parent); |
| 86 | CHECK_TOTAL_LENGTH (new); | 89 | eassert (0 <= TOTAL_LENGTH (new)); |
| 87 | STRING_SET_INTERVALS (parent, new); | 90 | string_set_intervals (parent, new); |
| 88 | new->position = 0; | 91 | new->position = 0; |
| 89 | } | 92 | } |
| 90 | 93 | ||
| 91 | SET_INTERVAL_OBJECT (new, parent); | 94 | interval_set_object (new, parent); |
| 92 | 95 | ||
| 93 | return new; | 96 | return new; |
| 94 | } | 97 | } |
| @@ -102,7 +105,7 @@ copy_properties (register INTERVAL source, register INTERVAL target) | |||
| 102 | return; | 105 | return; |
| 103 | 106 | ||
| 104 | COPY_INTERVAL_CACHE (source, target); | 107 | COPY_INTERVAL_CACHE (source, target); |
| 105 | target->plist = Fcopy_sequence (source->plist); | 108 | interval_set_plist (target, Fcopy_sequence (source->plist)); |
| 106 | } | 109 | } |
| 107 | 110 | ||
| 108 | /* Merge the properties of interval SOURCE into the properties | 111 | /* Merge the properties of interval SOURCE into the properties |
| @@ -138,7 +141,7 @@ merge_properties (register INTERVAL source, register INTERVAL target) | |||
| 138 | if (NILP (val)) | 141 | if (NILP (val)) |
| 139 | { | 142 | { |
| 140 | val = XCAR (o); | 143 | val = XCAR (o); |
| 141 | target->plist = Fcons (sym, Fcons (val, target->plist)); | 144 | interval_set_plist (target, Fcons (sym, Fcons (val, target->plist))); |
| 142 | } | 145 | } |
| 143 | o = XCDR (o); | 146 | o = XCDR (o); |
| 144 | } | 147 | } |
| @@ -207,10 +210,10 @@ void | |||
| 207 | traverse_intervals_noorder (INTERVAL tree, void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg) | 210 | traverse_intervals_noorder (INTERVAL tree, void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg) |
| 208 | { | 211 | { |
| 209 | /* Minimize stack usage. */ | 212 | /* Minimize stack usage. */ |
| 210 | while (!NULL_INTERVAL_P (tree)) | 213 | while (tree) |
| 211 | { | 214 | { |
| 212 | (*function) (tree, arg); | 215 | (*function) (tree, arg); |
| 213 | if (NULL_INTERVAL_P (tree->right)) | 216 | if (!tree->right) |
| 214 | tree = tree->left; | 217 | tree = tree->left; |
| 215 | else | 218 | else |
| 216 | { | 219 | { |
| @@ -227,7 +230,7 @@ void | |||
| 227 | traverse_intervals (INTERVAL tree, ptrdiff_t position, | 230 | traverse_intervals (INTERVAL tree, ptrdiff_t position, |
| 228 | void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg) | 231 | void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg) |
| 229 | { | 232 | { |
| 230 | while (!NULL_INTERVAL_P (tree)) | 233 | while (tree) |
| 231 | { | 234 | { |
| 232 | traverse_intervals (tree->left, position, function, arg); | 235 | traverse_intervals (tree->left, position, function, arg); |
| 233 | position += LEFT_TOTAL_LENGTH (tree); | 236 | position += LEFT_TOTAL_LENGTH (tree); |
| @@ -262,7 +265,7 @@ search_for_interval (INTERVAL i, INTERVAL tree) | |||
| 262 | { | 265 | { |
| 263 | icount = 0; | 266 | icount = 0; |
| 264 | search_interval = i; | 267 | search_interval = i; |
| 265 | found_interval = NULL_INTERVAL; | 268 | found_interval = NULL; |
| 266 | traverse_intervals_noorder (tree, &check_for_interval, Qnil); | 269 | traverse_intervals_noorder (tree, &check_for_interval, Qnil); |
| 267 | return found_interval; | 270 | return found_interval; |
| 268 | } | 271 | } |
| @@ -320,29 +323,29 @@ rotate_right (INTERVAL interval) | |||
| 320 | if (! ROOT_INTERVAL_P (interval)) | 323 | if (! ROOT_INTERVAL_P (interval)) |
| 321 | { | 324 | { |
| 322 | if (AM_LEFT_CHILD (interval)) | 325 | if (AM_LEFT_CHILD (interval)) |
| 323 | INTERVAL_PARENT (interval)->left = B; | 326 | interval_set_left (INTERVAL_PARENT (interval), B); |
| 324 | else | 327 | else |
| 325 | INTERVAL_PARENT (interval)->right = B; | 328 | interval_set_right (INTERVAL_PARENT (interval), B); |
| 326 | } | 329 | } |
| 327 | COPY_INTERVAL_PARENT (B, interval); | 330 | interval_copy_parent (B, interval); |
| 328 | 331 | ||
| 329 | /* Make B the parent of A */ | 332 | /* Make B the parent of A */ |
| 330 | i = B->right; | 333 | i = B->right; |
| 331 | B->right = interval; | 334 | interval_set_right (B, interval); |
| 332 | SET_INTERVAL_PARENT (interval, B); | 335 | interval_set_parent (interval, B); |
| 333 | 336 | ||
| 334 | /* Make A point to c */ | 337 | /* Make A point to c */ |
| 335 | interval->left = i; | 338 | interval_set_left (interval, i); |
| 336 | if (! NULL_INTERVAL_P (i)) | 339 | if (i) |
| 337 | SET_INTERVAL_PARENT (i, interval); | 340 | interval_set_parent (i, interval); |
| 338 | 341 | ||
| 339 | /* A's total length is decreased by the length of B and its left child. */ | 342 | /* A's total length is decreased by the length of B and its left child. */ |
| 340 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); | 343 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); |
| 341 | CHECK_TOTAL_LENGTH (interval); | 344 | eassert (0 <= TOTAL_LENGTH (interval)); |
| 342 | 345 | ||
| 343 | /* B must have the same total length of A. */ | 346 | /* B must have the same total length of A. */ |
| 344 | B->total_length = old_total; | 347 | B->total_length = old_total; |
| 345 | CHECK_TOTAL_LENGTH (B); | 348 | eassert (0 <= TOTAL_LENGTH (B)); |
| 346 | 349 | ||
| 347 | return B; | 350 | return B; |
| 348 | } | 351 | } |
| @@ -367,29 +370,29 @@ rotate_left (INTERVAL interval) | |||
| 367 | if (! ROOT_INTERVAL_P (interval)) | 370 | if (! ROOT_INTERVAL_P (interval)) |
| 368 | { | 371 | { |
| 369 | if (AM_LEFT_CHILD (interval)) | 372 | if (AM_LEFT_CHILD (interval)) |
| 370 | INTERVAL_PARENT (interval)->left = B; | 373 | interval_set_left (INTERVAL_PARENT (interval), B); |
| 371 | else | 374 | else |
| 372 | INTERVAL_PARENT (interval)->right = B; | 375 | interval_set_right (INTERVAL_PARENT (interval), B); |
| 373 | } | 376 | } |
| 374 | COPY_INTERVAL_PARENT (B, interval); | 377 | interval_copy_parent (B, interval); |
| 375 | 378 | ||
| 376 | /* Make B the parent of A */ | 379 | /* Make B the parent of A */ |
| 377 | i = B->left; | 380 | i = B->left; |
| 378 | B->left = interval; | 381 | interval_set_left (B, interval); |
| 379 | SET_INTERVAL_PARENT (interval, B); | 382 | interval_set_parent (interval, B); |
| 380 | 383 | ||
| 381 | /* Make A point to c */ | 384 | /* Make A point to c */ |
| 382 | interval->right = i; | 385 | interval_set_right (interval, i); |
| 383 | if (! NULL_INTERVAL_P (i)) | 386 | if (i) |
| 384 | SET_INTERVAL_PARENT (i, interval); | 387 | interval_set_parent (i, interval); |
| 385 | 388 | ||
| 386 | /* A's total length is decreased by the length of B and its right child. */ | 389 | /* A's total length is decreased by the length of B and its right child. */ |
| 387 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); | 390 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); |
| 388 | CHECK_TOTAL_LENGTH (interval); | 391 | eassert (0 <= TOTAL_LENGTH (interval)); |
| 389 | 392 | ||
| 390 | /* B must have the same total length of A. */ | 393 | /* B must have the same total length of A. */ |
| 391 | B->total_length = old_total; | 394 | B->total_length = old_total; |
| 392 | CHECK_TOTAL_LENGTH (B); | 395 | eassert (0 <= TOTAL_LENGTH (B)); |
| 393 | 396 | ||
| 394 | return B; | 397 | return B; |
| 395 | } | 398 | } |
| @@ -453,9 +456,9 @@ balance_possible_root_interval (register INTERVAL interval) | |||
| 453 | if (have_parent) | 456 | if (have_parent) |
| 454 | { | 457 | { |
| 455 | if (BUFFERP (parent)) | 458 | if (BUFFERP (parent)) |
| 456 | BUF_INTERVALS (XBUFFER (parent)) = interval; | 459 | buffer_set_intervals (XBUFFER (parent), interval); |
| 457 | else if (STRINGP (parent)) | 460 | else if (STRINGP (parent)) |
| 458 | STRING_SET_INTERVALS (parent, interval); | 461 | string_set_intervals (parent, interval); |
| 459 | } | 462 | } |
| 460 | 463 | ||
| 461 | return interval; | 464 | return interval; |
| @@ -480,12 +483,22 @@ balance_intervals_internal (register INTERVAL tree) | |||
| 480 | INTERVAL | 483 | INTERVAL |
| 481 | balance_intervals (INTERVAL tree) | 484 | balance_intervals (INTERVAL tree) |
| 482 | { | 485 | { |
| 483 | if (tree == NULL_INTERVAL) | 486 | return tree ? balance_intervals_internal (tree) : NULL; |
| 484 | return NULL_INTERVAL; | 487 | } |
| 488 | |||
| 489 | /* Rebalance text properties of B. */ | ||
| 490 | |||
| 491 | static void | ||
| 492 | buffer_balance_intervals (struct buffer *b) | ||
| 493 | { | ||
| 494 | INTERVAL i; | ||
| 485 | 495 | ||
| 486 | return balance_intervals_internal (tree); | 496 | eassert (b != NULL); |
| 497 | i = buffer_get_intervals (b); | ||
| 498 | if (i) | ||
| 499 | buffer_set_intervals (b, balance_an_interval (i)); | ||
| 487 | } | 500 | } |
| 488 | 501 | ||
| 489 | /* Split INTERVAL into two pieces, starting the second piece at | 502 | /* Split INTERVAL into two pieces, starting the second piece at |
| 490 | character position OFFSET (counting from 0), relative to INTERVAL. | 503 | character position OFFSET (counting from 0), relative to INTERVAL. |
| 491 | INTERVAL becomes the left-hand piece, and the right-hand piece | 504 | INTERVAL becomes the left-hand piece, and the right-hand piece |
| @@ -507,22 +520,22 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) | |||
| 507 | ptrdiff_t new_length = LENGTH (interval) - offset; | 520 | ptrdiff_t new_length = LENGTH (interval) - offset; |
| 508 | 521 | ||
| 509 | new->position = position + offset; | 522 | new->position = position + offset; |
| 510 | SET_INTERVAL_PARENT (new, interval); | 523 | interval_set_parent (new, interval); |
| 511 | 524 | ||
| 512 | if (NULL_RIGHT_CHILD (interval)) | 525 | if (NULL_RIGHT_CHILD (interval)) |
| 513 | { | 526 | { |
| 514 | interval->right = new; | 527 | interval_set_right (interval, new); |
| 515 | new->total_length = new_length; | 528 | new->total_length = new_length; |
| 516 | CHECK_TOTAL_LENGTH (new); | 529 | eassert (0 <= TOTAL_LENGTH (new)); |
| 517 | } | 530 | } |
| 518 | else | 531 | else |
| 519 | { | 532 | { |
| 520 | /* Insert the new node between INTERVAL and its right child. */ | 533 | /* Insert the new node between INTERVAL and its right child. */ |
| 521 | new->right = interval->right; | 534 | interval_set_right (new, interval->right); |
| 522 | SET_INTERVAL_PARENT (interval->right, new); | 535 | interval_set_parent (interval->right, new); |
| 523 | interval->right = new; | 536 | interval_set_right (interval, new); |
| 524 | new->total_length = new_length + new->right->total_length; | 537 | new->total_length = new_length + new->right->total_length; |
| 525 | CHECK_TOTAL_LENGTH (new); | 538 | eassert (0 <= TOTAL_LENGTH (new)); |
| 526 | balance_an_interval (new); | 539 | balance_an_interval (new); |
| 527 | } | 540 | } |
| 528 | 541 | ||
| @@ -552,22 +565,22 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) | |||
| 552 | 565 | ||
| 553 | new->position = interval->position; | 566 | new->position = interval->position; |
| 554 | interval->position = interval->position + offset; | 567 | interval->position = interval->position + offset; |
| 555 | SET_INTERVAL_PARENT (new, interval); | 568 | interval_set_parent (new, interval); |
| 556 | 569 | ||
| 557 | if (NULL_LEFT_CHILD (interval)) | 570 | if (NULL_LEFT_CHILD (interval)) |
| 558 | { | 571 | { |
| 559 | interval->left = new; | 572 | interval_set_left (interval, new); |
| 560 | new->total_length = new_length; | 573 | new->total_length = new_length; |
| 561 | CHECK_TOTAL_LENGTH (new); | 574 | eassert (0 <= TOTAL_LENGTH (new)); |
| 562 | } | 575 | } |
| 563 | else | 576 | else |
| 564 | { | 577 | { |
| 565 | /* Insert the new node between INTERVAL and its left child. */ | 578 | /* Insert the new node between INTERVAL and its left child. */ |
| 566 | new->left = interval->left; | 579 | interval_set_left (new, interval->left); |
| 567 | SET_INTERVAL_PARENT (new->left, new); | 580 | interval_set_parent (new->left, new); |
| 568 | interval->left = new; | 581 | interval_set_left (interval, new); |
| 569 | new->total_length = new_length + new->left->total_length; | 582 | new->total_length = new_length + new->left->total_length; |
| 570 | CHECK_TOTAL_LENGTH (new); | 583 | eassert (0 <= TOTAL_LENGTH (new)); |
| 571 | balance_an_interval (new); | 584 | balance_an_interval (new); |
| 572 | } | 585 | } |
| 573 | 586 | ||
| @@ -589,7 +602,7 @@ interval_start_pos (INTERVAL source) | |||
| 589 | { | 602 | { |
| 590 | Lisp_Object parent; | 603 | Lisp_Object parent; |
| 591 | 604 | ||
| 592 | if (NULL_INTERVAL_P (source)) | 605 | if (!source) |
| 593 | return 0; | 606 | return 0; |
| 594 | 607 | ||
| 595 | if (! INTERVAL_HAS_OBJECT (source)) | 608 | if (! INTERVAL_HAS_OBJECT (source)) |
| @@ -617,8 +630,8 @@ find_interval (register INTERVAL tree, register ptrdiff_t position) | |||
| 617 | to POSITION. */ | 630 | to POSITION. */ |
| 618 | register ptrdiff_t relative_position; | 631 | register ptrdiff_t relative_position; |
| 619 | 632 | ||
| 620 | if (NULL_INTERVAL_P (tree)) | 633 | if (!tree) |
| 621 | return NULL_INTERVAL; | 634 | return NULL; |
| 622 | 635 | ||
| 623 | relative_position = position; | 636 | relative_position = position; |
| 624 | if (INTERVAL_HAS_OBJECT (tree)) | 637 | if (INTERVAL_HAS_OBJECT (tree)) |
| @@ -669,8 +682,8 @@ next_interval (register INTERVAL interval) | |||
| 669 | register INTERVAL i = interval; | 682 | register INTERVAL i = interval; |
| 670 | register ptrdiff_t next_position; | 683 | register ptrdiff_t next_position; |
| 671 | 684 | ||
| 672 | if (NULL_INTERVAL_P (i)) | 685 | if (!i) |
| 673 | return NULL_INTERVAL; | 686 | return NULL; |
| 674 | next_position = interval->position + LENGTH (interval); | 687 | next_position = interval->position + LENGTH (interval); |
| 675 | 688 | ||
| 676 | if (! NULL_RIGHT_CHILD (i)) | 689 | if (! NULL_RIGHT_CHILD (i)) |
| @@ -695,7 +708,7 @@ next_interval (register INTERVAL interval) | |||
| 695 | i = INTERVAL_PARENT (i); | 708 | i = INTERVAL_PARENT (i); |
| 696 | } | 709 | } |
| 697 | 710 | ||
| 698 | return NULL_INTERVAL; | 711 | return NULL; |
| 699 | } | 712 | } |
| 700 | 713 | ||
| 701 | /* Find the preceding interval (lexicographically) to INTERVAL. | 714 | /* Find the preceding interval (lexicographically) to INTERVAL. |
| @@ -707,8 +720,8 @@ previous_interval (register INTERVAL interval) | |||
| 707 | { | 720 | { |
| 708 | register INTERVAL i; | 721 | register INTERVAL i; |
| 709 | 722 | ||
| 710 | if (NULL_INTERVAL_P (interval)) | 723 | if (!interval) |
| 711 | return NULL_INTERVAL; | 724 | return NULL; |
| 712 | 725 | ||
| 713 | if (! NULL_LEFT_CHILD (interval)) | 726 | if (! NULL_LEFT_CHILD (interval)) |
| 714 | { | 727 | { |
| @@ -733,7 +746,7 @@ previous_interval (register INTERVAL interval) | |||
| 733 | i = INTERVAL_PARENT (i); | 746 | i = INTERVAL_PARENT (i); |
| 734 | } | 747 | } |
| 735 | 748 | ||
| 736 | return NULL_INTERVAL; | 749 | return NULL; |
| 737 | } | 750 | } |
| 738 | 751 | ||
| 739 | /* Find the interval containing POS given some non-NULL INTERVAL | 752 | /* Find the interval containing POS given some non-NULL INTERVAL |
| @@ -744,8 +757,8 @@ previous_interval (register INTERVAL interval) | |||
| 744 | INTERVAL | 757 | INTERVAL |
| 745 | update_interval (register INTERVAL i, ptrdiff_t pos) | 758 | update_interval (register INTERVAL i, ptrdiff_t pos) |
| 746 | { | 759 | { |
| 747 | if (NULL_INTERVAL_P (i)) | 760 | if (!i) |
| 748 | return NULL_INTERVAL; | 761 | return NULL; |
| 749 | 762 | ||
| 750 | while (1) | 763 | while (1) |
| 751 | { | 764 | { |
| @@ -918,7 +931,7 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 918 | for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) | 931 | for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) |
| 919 | { | 932 | { |
| 920 | temp->total_length += length; | 933 | temp->total_length += length; |
| 921 | CHECK_TOTAL_LENGTH (temp); | 934 | eassert (0 <= TOTAL_LENGTH (temp)); |
| 922 | temp = balance_possible_root_interval (temp); | 935 | temp = balance_possible_root_interval (temp); |
| 923 | } | 936 | } |
| 924 | 937 | ||
| @@ -938,25 +951,23 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 938 | struct interval newi; | 951 | struct interval newi; |
| 939 | 952 | ||
| 940 | RESET_INTERVAL (&newi); | 953 | RESET_INTERVAL (&newi); |
| 941 | pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist; | 954 | pleft = prev ? prev->plist : Qnil; |
| 942 | pright = NULL_INTERVAL_P (i) ? Qnil : i->plist; | 955 | pright = i ? i->plist : Qnil; |
| 943 | newi.plist = merge_properties_sticky (pleft, pright); | 956 | interval_set_plist (&newi, merge_properties_sticky (pleft, pright)); |
| 944 | 957 | ||
| 945 | if (! prev) /* i.e. position == BEG */ | 958 | if (! prev) /* i.e. position == BEG */ |
| 946 | { | 959 | { |
| 947 | if (! intervals_equal (i, &newi)) | 960 | if (! intervals_equal (i, &newi)) |
| 948 | { | 961 | { |
| 949 | i = split_interval_left (i, length); | 962 | i = split_interval_left (i, length); |
| 950 | i->plist = newi.plist; | 963 | interval_set_plist (i, newi.plist); |
| 951 | } | 964 | } |
| 952 | } | 965 | } |
| 953 | else if (! intervals_equal (prev, &newi)) | 966 | else if (! intervals_equal (prev, &newi)) |
| 954 | { | 967 | { |
| 955 | prev = split_interval_right (prev, | 968 | prev = split_interval_right (prev, position - prev->position); |
| 956 | position - prev->position); | 969 | interval_set_plist (prev, newi.plist); |
| 957 | prev->plist = newi.plist; | 970 | if (i && intervals_equal (prev, i)) |
| 958 | if (! NULL_INTERVAL_P (i) | ||
| 959 | && intervals_equal (prev, i)) | ||
| 960 | merge_interval_right (prev); | 971 | merge_interval_right (prev); |
| 961 | } | 972 | } |
| 962 | 973 | ||
| @@ -976,7 +987,7 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 976 | for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) | 987 | for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) |
| 977 | { | 988 | { |
| 978 | temp->total_length += length; | 989 | temp->total_length += length; |
| 979 | CHECK_TOTAL_LENGTH (temp); | 990 | eassert (0 <= TOTAL_LENGTH (temp)); |
| 980 | temp = balance_possible_root_interval (temp); | 991 | temp = balance_possible_root_interval (temp); |
| 981 | } | 992 | } |
| 982 | } | 993 | } |
| @@ -1165,23 +1176,23 @@ delete_node (register INTERVAL i) | |||
| 1165 | register INTERVAL migrate, this; | 1176 | register INTERVAL migrate, this; |
| 1166 | register ptrdiff_t migrate_amt; | 1177 | register ptrdiff_t migrate_amt; |
| 1167 | 1178 | ||
| 1168 | if (NULL_INTERVAL_P (i->left)) | 1179 | if (!i->left) |
| 1169 | return i->right; | 1180 | return i->right; |
| 1170 | if (NULL_INTERVAL_P (i->right)) | 1181 | if (!i->right) |
| 1171 | return i->left; | 1182 | return i->left; |
| 1172 | 1183 | ||
| 1173 | migrate = i->left; | 1184 | migrate = i->left; |
| 1174 | migrate_amt = i->left->total_length; | 1185 | migrate_amt = i->left->total_length; |
| 1175 | this = i->right; | 1186 | this = i->right; |
| 1176 | this->total_length += migrate_amt; | 1187 | this->total_length += migrate_amt; |
| 1177 | while (! NULL_INTERVAL_P (this->left)) | 1188 | while (this->left) |
| 1178 | { | 1189 | { |
| 1179 | this = this->left; | 1190 | this = this->left; |
| 1180 | this->total_length += migrate_amt; | 1191 | this->total_length += migrate_amt; |
| 1181 | } | 1192 | } |
| 1182 | CHECK_TOTAL_LENGTH (this); | 1193 | eassert (0 <= TOTAL_LENGTH (this)); |
| 1183 | this->left = migrate; | 1194 | interval_set_left (this, migrate); |
| 1184 | SET_INTERVAL_PARENT (migrate, this); | 1195 | interval_set_parent (migrate, this); |
| 1185 | 1196 | ||
| 1186 | return i->right; | 1197 | return i->right; |
| 1187 | } | 1198 | } |
| @@ -1205,13 +1216,13 @@ delete_interval (register INTERVAL i) | |||
| 1205 | Lisp_Object owner; | 1216 | Lisp_Object owner; |
| 1206 | GET_INTERVAL_OBJECT (owner, i); | 1217 | GET_INTERVAL_OBJECT (owner, i); |
| 1207 | parent = delete_node (i); | 1218 | parent = delete_node (i); |
| 1208 | if (! NULL_INTERVAL_P (parent)) | 1219 | if (parent) |
| 1209 | SET_INTERVAL_OBJECT (parent, owner); | 1220 | interval_set_object (parent, owner); |
| 1210 | 1221 | ||
| 1211 | if (BUFFERP (owner)) | 1222 | if (BUFFERP (owner)) |
| 1212 | BUF_INTERVALS (XBUFFER (owner)) = parent; | 1223 | buffer_set_intervals (XBUFFER (owner), parent); |
| 1213 | else if (STRINGP (owner)) | 1224 | else if (STRINGP (owner)) |
| 1214 | STRING_SET_INTERVALS (owner, parent); | 1225 | string_set_intervals (owner, parent); |
| 1215 | else | 1226 | else |
| 1216 | abort (); | 1227 | abort (); |
| 1217 | 1228 | ||
| @@ -1221,15 +1232,15 @@ delete_interval (register INTERVAL i) | |||
| 1221 | parent = INTERVAL_PARENT (i); | 1232 | parent = INTERVAL_PARENT (i); |
| 1222 | if (AM_LEFT_CHILD (i)) | 1233 | if (AM_LEFT_CHILD (i)) |
| 1223 | { | 1234 | { |
| 1224 | parent->left = delete_node (i); | 1235 | interval_set_left (parent, delete_node (i)); |
| 1225 | if (! NULL_INTERVAL_P (parent->left)) | 1236 | if (parent->left) |
| 1226 | SET_INTERVAL_PARENT (parent->left, parent); | 1237 | interval_set_parent (parent->left, parent); |
| 1227 | } | 1238 | } |
| 1228 | else | 1239 | else |
| 1229 | { | 1240 | { |
| 1230 | parent->right = delete_node (i); | 1241 | interval_set_right (parent, delete_node (i)); |
| 1231 | if (! NULL_INTERVAL_P (parent->right)) | 1242 | if (parent->right) |
| 1232 | SET_INTERVAL_PARENT (parent->right, parent); | 1243 | interval_set_parent (parent->right, parent); |
| 1233 | } | 1244 | } |
| 1234 | } | 1245 | } |
| 1235 | 1246 | ||
| @@ -1251,7 +1262,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1251 | { | 1262 | { |
| 1252 | register ptrdiff_t relative_position = from; | 1263 | register ptrdiff_t relative_position = from; |
| 1253 | 1264 | ||
| 1254 | if (NULL_INTERVAL_P (tree)) | 1265 | if (!tree) |
| 1255 | return 0; | 1266 | return 0; |
| 1256 | 1267 | ||
| 1257 | /* Left branch. */ | 1268 | /* Left branch. */ |
| @@ -1261,7 +1272,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1261 | relative_position, | 1272 | relative_position, |
| 1262 | amount); | 1273 | amount); |
| 1263 | tree->total_length -= subtract; | 1274 | tree->total_length -= subtract; |
| 1264 | CHECK_TOTAL_LENGTH (tree); | 1275 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1265 | return subtract; | 1276 | return subtract; |
| 1266 | } | 1277 | } |
| 1267 | /* Right branch. */ | 1278 | /* Right branch. */ |
| @@ -1276,7 +1287,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1276 | relative_position, | 1287 | relative_position, |
| 1277 | amount); | 1288 | amount); |
| 1278 | tree->total_length -= subtract; | 1289 | tree->total_length -= subtract; |
| 1279 | CHECK_TOTAL_LENGTH (tree); | 1290 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1280 | return subtract; | 1291 | return subtract; |
| 1281 | } | 1292 | } |
| 1282 | /* Here -- this node. */ | 1293 | /* Here -- this node. */ |
| @@ -1291,7 +1302,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1291 | amount = my_amount; | 1302 | amount = my_amount; |
| 1292 | 1303 | ||
| 1293 | tree->total_length -= amount; | 1304 | tree->total_length -= amount; |
| 1294 | CHECK_TOTAL_LENGTH (tree); | 1305 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1295 | if (LENGTH (tree) == 0) | 1306 | if (LENGTH (tree) == 0) |
| 1296 | delete_interval (tree); | 1307 | delete_interval (tree); |
| 1297 | 1308 | ||
| @@ -1311,14 +1322,14 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1311 | ptrdiff_t start, ptrdiff_t length) | 1322 | ptrdiff_t start, ptrdiff_t length) |
| 1312 | { | 1323 | { |
| 1313 | register ptrdiff_t left_to_delete = length; | 1324 | register ptrdiff_t left_to_delete = length; |
| 1314 | register INTERVAL tree = BUF_INTERVALS (buffer); | 1325 | register INTERVAL tree = buffer_get_intervals (buffer); |
| 1315 | Lisp_Object parent; | 1326 | Lisp_Object parent; |
| 1316 | ptrdiff_t offset; | 1327 | ptrdiff_t offset; |
| 1317 | 1328 | ||
| 1318 | GET_INTERVAL_OBJECT (parent, tree); | 1329 | GET_INTERVAL_OBJECT (parent, tree); |
| 1319 | offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); | 1330 | offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); |
| 1320 | 1331 | ||
| 1321 | if (NULL_INTERVAL_P (tree)) | 1332 | if (!tree) |
| 1322 | return; | 1333 | return; |
| 1323 | 1334 | ||
| 1324 | eassert (start <= offset + TOTAL_LENGTH (tree) | 1335 | eassert (start <= offset + TOTAL_LENGTH (tree) |
| @@ -1326,14 +1337,14 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1326 | 1337 | ||
| 1327 | if (length == TOTAL_LENGTH (tree)) | 1338 | if (length == TOTAL_LENGTH (tree)) |
| 1328 | { | 1339 | { |
| 1329 | BUF_INTERVALS (buffer) = NULL_INTERVAL; | 1340 | buffer_set_intervals (buffer, NULL); |
| 1330 | return; | 1341 | return; |
| 1331 | } | 1342 | } |
| 1332 | 1343 | ||
| 1333 | if (ONLY_INTERVAL_P (tree)) | 1344 | if (ONLY_INTERVAL_P (tree)) |
| 1334 | { | 1345 | { |
| 1335 | tree->total_length -= length; | 1346 | tree->total_length -= length; |
| 1336 | CHECK_TOTAL_LENGTH (tree); | 1347 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1337 | return; | 1348 | return; |
| 1338 | } | 1349 | } |
| 1339 | 1350 | ||
| @@ -1343,10 +1354,10 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1343 | { | 1354 | { |
| 1344 | left_to_delete -= interval_deletion_adjustment (tree, start - offset, | 1355 | left_to_delete -= interval_deletion_adjustment (tree, start - offset, |
| 1345 | left_to_delete); | 1356 | left_to_delete); |
| 1346 | tree = BUF_INTERVALS (buffer); | 1357 | tree = buffer_get_intervals (buffer); |
| 1347 | if (left_to_delete == tree->total_length) | 1358 | if (left_to_delete == tree->total_length) |
| 1348 | { | 1359 | { |
| 1349 | BUF_INTERVALS (buffer) = NULL_INTERVAL; | 1360 | buffer_set_intervals (buffer, NULL); |
| 1350 | return; | 1361 | return; |
| 1351 | } | 1362 | } |
| 1352 | } | 1363 | } |
| @@ -1355,20 +1366,17 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1355 | /* Make the adjustments necessary to the interval tree of BUFFER to | 1366 | /* Make the adjustments necessary to the interval tree of BUFFER to |
| 1356 | represent an addition or deletion of LENGTH characters starting | 1367 | represent an addition or deletion of LENGTH characters starting |
| 1357 | at position START. Addition or deletion is indicated by the sign | 1368 | at position START. Addition or deletion is indicated by the sign |
| 1358 | of LENGTH. | 1369 | of LENGTH. */ |
| 1359 | |||
| 1360 | The two inline functions (one static) pacify Sun C 5.8, a pre-C99 | ||
| 1361 | compiler that does not allow calling a static function (here, | ||
| 1362 | adjust_intervals_for_deletion) from a non-static inline function. */ | ||
| 1363 | 1370 | ||
| 1364 | void | 1371 | void |
| 1365 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) | 1372 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) |
| 1366 | { | 1373 | { |
| 1367 | if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0) | 1374 | if (!buffer_get_intervals (buffer) || length == 0) |
| 1368 | return; | 1375 | return; |
| 1369 | 1376 | ||
| 1370 | if (length > 0) | 1377 | if (length > 0) |
| 1371 | adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length); | 1378 | adjust_intervals_for_insertion (buffer_get_intervals (buffer), |
| 1379 | start, length); | ||
| 1372 | else | 1380 | else |
| 1373 | { | 1381 | { |
| 1374 | IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();) | 1382 | IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();) |
| @@ -1399,19 +1407,19 @@ merge_interval_right (register INTERVAL i) | |||
| 1399 | while (! NULL_LEFT_CHILD (successor)) | 1407 | while (! NULL_LEFT_CHILD (successor)) |
| 1400 | { | 1408 | { |
| 1401 | successor->total_length += absorb; | 1409 | successor->total_length += absorb; |
| 1402 | CHECK_TOTAL_LENGTH (successor); | 1410 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1403 | successor = successor->left; | 1411 | successor = successor->left; |
| 1404 | } | 1412 | } |
| 1405 | 1413 | ||
| 1406 | successor->total_length += absorb; | 1414 | successor->total_length += absorb; |
| 1407 | CHECK_TOTAL_LENGTH (successor); | 1415 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1408 | delete_interval (i); | 1416 | delete_interval (i); |
| 1409 | return successor; | 1417 | return successor; |
| 1410 | } | 1418 | } |
| 1411 | 1419 | ||
| 1412 | /* Zero out this interval. */ | 1420 | /* Zero out this interval. */ |
| 1413 | i->total_length -= absorb; | 1421 | i->total_length -= absorb; |
| 1414 | CHECK_TOTAL_LENGTH (i); | 1422 | eassert (0 <= TOTAL_LENGTH (i)); |
| 1415 | 1423 | ||
| 1416 | successor = i; | 1424 | successor = i; |
| 1417 | while (! NULL_PARENT (successor)) /* It's above us. Subtract as | 1425 | while (! NULL_PARENT (successor)) /* It's above us. Subtract as |
| @@ -1426,7 +1434,7 @@ merge_interval_right (register INTERVAL i) | |||
| 1426 | 1434 | ||
| 1427 | successor = INTERVAL_PARENT (successor); | 1435 | successor = INTERVAL_PARENT (successor); |
| 1428 | successor->total_length -= absorb; | 1436 | successor->total_length -= absorb; |
| 1429 | CHECK_TOTAL_LENGTH (successor); | 1437 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1430 | } | 1438 | } |
| 1431 | 1439 | ||
| 1432 | /* This must be the rightmost or last interval and cannot | 1440 | /* This must be the rightmost or last interval and cannot |
| @@ -1455,19 +1463,19 @@ merge_interval_left (register INTERVAL i) | |||
| 1455 | while (! NULL_RIGHT_CHILD (predecessor)) | 1463 | while (! NULL_RIGHT_CHILD (predecessor)) |
| 1456 | { | 1464 | { |
| 1457 | predecessor->total_length += absorb; | 1465 | predecessor->total_length += absorb; |
| 1458 | CHECK_TOTAL_LENGTH (predecessor); | 1466 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1459 | predecessor = predecessor->right; | 1467 | predecessor = predecessor->right; |
| 1460 | } | 1468 | } |
| 1461 | 1469 | ||
| 1462 | predecessor->total_length += absorb; | 1470 | predecessor->total_length += absorb; |
| 1463 | CHECK_TOTAL_LENGTH (predecessor); | 1471 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1464 | delete_interval (i); | 1472 | delete_interval (i); |
| 1465 | return predecessor; | 1473 | return predecessor; |
| 1466 | } | 1474 | } |
| 1467 | 1475 | ||
| 1468 | /* Zero out this interval. */ | 1476 | /* Zero out this interval. */ |
| 1469 | i->total_length -= absorb; | 1477 | i->total_length -= absorb; |
| 1470 | CHECK_TOTAL_LENGTH (i); | 1478 | eassert (0 <= TOTAL_LENGTH (i)); |
| 1471 | 1479 | ||
| 1472 | predecessor = i; | 1480 | predecessor = i; |
| 1473 | while (! NULL_PARENT (predecessor)) /* It's above us. Go up, | 1481 | while (! NULL_PARENT (predecessor)) /* It's above us. Go up, |
| @@ -1482,7 +1490,7 @@ merge_interval_left (register INTERVAL i) | |||
| 1482 | 1490 | ||
| 1483 | predecessor = INTERVAL_PARENT (predecessor); | 1491 | predecessor = INTERVAL_PARENT (predecessor); |
| 1484 | predecessor->total_length -= absorb; | 1492 | predecessor->total_length -= absorb; |
| 1485 | CHECK_TOTAL_LENGTH (predecessor); | 1493 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1486 | } | 1494 | } |
| 1487 | 1495 | ||
| 1488 | /* This must be the leftmost or first interval and cannot | 1496 | /* This must be the leftmost or first interval and cannot |
| @@ -1500,13 +1508,13 @@ reproduce_tree (INTERVAL source, INTERVAL parent) | |||
| 1500 | { | 1508 | { |
| 1501 | register INTERVAL t = make_interval (); | 1509 | register INTERVAL t = make_interval (); |
| 1502 | 1510 | ||
| 1503 | memcpy (t, source, INTERVAL_SIZE); | 1511 | memcpy (t, source, sizeof *t); |
| 1504 | copy_properties (source, t); | 1512 | copy_properties (source, t); |
| 1505 | SET_INTERVAL_PARENT (t, parent); | 1513 | interval_set_parent (t, parent); |
| 1506 | if (! NULL_LEFT_CHILD (source)) | 1514 | if (! NULL_LEFT_CHILD (source)) |
| 1507 | t->left = reproduce_tree (source->left, t); | 1515 | interval_set_left (t, reproduce_tree (source->left, t)); |
| 1508 | if (! NULL_RIGHT_CHILD (source)) | 1516 | if (! NULL_RIGHT_CHILD (source)) |
| 1509 | t->right = reproduce_tree (source->right, t); | 1517 | interval_set_right (t, reproduce_tree (source->right, t)); |
| 1510 | 1518 | ||
| 1511 | return t; | 1519 | return t; |
| 1512 | } | 1520 | } |
| @@ -1516,13 +1524,13 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent) | |||
| 1516 | { | 1524 | { |
| 1517 | register INTERVAL t = make_interval (); | 1525 | register INTERVAL t = make_interval (); |
| 1518 | 1526 | ||
| 1519 | memcpy (t, source, INTERVAL_SIZE); | 1527 | memcpy (t, source, sizeof *t); |
| 1520 | copy_properties (source, t); | 1528 | copy_properties (source, t); |
| 1521 | SET_INTERVAL_OBJECT (t, parent); | 1529 | interval_set_object (t, parent); |
| 1522 | if (! NULL_LEFT_CHILD (source)) | 1530 | if (! NULL_LEFT_CHILD (source)) |
| 1523 | t->left = reproduce_tree (source->left, t); | 1531 | interval_set_left (t, reproduce_tree (source->left, t)); |
| 1524 | if (! NULL_RIGHT_CHILD (source)) | 1532 | if (! NULL_RIGHT_CHILD (source)) |
| 1525 | t->right = reproduce_tree (source->right, t); | 1533 | interval_set_right (t, reproduce_tree (source->right, t)); |
| 1526 | 1534 | ||
| 1527 | return t; | 1535 | return t; |
| 1528 | } | 1536 | } |
| @@ -1550,11 +1558,9 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent) | |||
| 1550 | cases -- either insertion happened in the middle of some interval, | 1558 | cases -- either insertion happened in the middle of some interval, |
| 1551 | or between two intervals. | 1559 | or between two intervals. |
| 1552 | 1560 | ||
| 1553 | If the text goes into the middle of an interval, then new | 1561 | If the text goes into the middle of an interval, then new intervals |
| 1554 | intervals are created in the middle with only the properties of | 1562 | are created in the middle, and new text has the union of its properties |
| 1555 | the new text, *unless* the macro MERGE_INSERTIONS is true, in | 1563 | and those of the text into which it was inserted. |
| 1556 | which case the new text has the union of its properties and those | ||
| 1557 | of the text into which it was inserted. | ||
| 1558 | 1564 | ||
| 1559 | If the text goes between two intervals, then if neither interval | 1565 | If the text goes between two intervals, then if neither interval |
| 1560 | had its appropriate sticky property set (front_sticky, rear_sticky), | 1566 | had its appropriate sticky property set (front_sticky, rear_sticky), |
| @@ -1575,53 +1581,56 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1575 | register INTERVAL tree; | 1581 | register INTERVAL tree; |
| 1576 | ptrdiff_t over_used; | 1582 | ptrdiff_t over_used; |
| 1577 | 1583 | ||
| 1578 | tree = BUF_INTERVALS (buffer); | 1584 | tree = buffer_get_intervals (buffer); |
| 1579 | 1585 | ||
| 1580 | /* If the new text has no properties, then with inheritance it | 1586 | /* If the new text has no properties, then with inheritance it |
| 1581 | becomes part of whatever interval it was inserted into. | 1587 | becomes part of whatever interval it was inserted into. |
| 1582 | To prevent inheritance, we must clear out the properties | 1588 | To prevent inheritance, we must clear out the properties |
| 1583 | of the newly inserted text. */ | 1589 | of the newly inserted text. */ |
| 1584 | if (NULL_INTERVAL_P (source)) | 1590 | if (!source) |
| 1585 | { | 1591 | { |
| 1586 | Lisp_Object buf; | 1592 | Lisp_Object buf; |
| 1587 | if (!inherit && !NULL_INTERVAL_P (tree) && length > 0) | 1593 | if (!inherit && tree && length > 0) |
| 1588 | { | 1594 | { |
| 1589 | XSETBUFFER (buf, buffer); | 1595 | XSETBUFFER (buf, buffer); |
| 1590 | set_text_properties_1 (make_number (position), | 1596 | set_text_properties_1 (make_number (position), |
| 1591 | make_number (position + length), | 1597 | make_number (position + length), |
| 1592 | Qnil, buf, 0); | 1598 | Qnil, buf, 0); |
| 1593 | } | 1599 | } |
| 1594 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) | 1600 | /* Shouldn't be necessary. --Stef */ |
| 1595 | /* Shouldn't be necessary. --Stef */ | 1601 | buffer_balance_intervals (buffer); |
| 1596 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); | ||
| 1597 | return; | 1602 | return; |
| 1598 | } | 1603 | } |
| 1599 | 1604 | ||
| 1600 | eassert (length == TOTAL_LENGTH (source)); | 1605 | eassert (length == TOTAL_LENGTH (source)); |
| 1601 | 1606 | ||
| 1602 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length) | 1607 | if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length) |
| 1603 | { /* The inserted text constitutes the whole buffer, so | 1608 | { |
| 1609 | /* The inserted text constitutes the whole buffer, so | ||
| 1604 | simply copy over the interval structure. */ | 1610 | simply copy over the interval structure. */ |
| 1605 | Lisp_Object buf; | 1611 | Lisp_Object buf; |
| 1606 | XSETBUFFER (buf, buffer); | 1612 | |
| 1607 | BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf); | 1613 | XSETBUFFER (buf, buffer); |
| 1608 | BUF_INTERVALS (buffer)->position = BUF_BEG (buffer); | 1614 | buffer_set_intervals (buffer, reproduce_tree_obj (source, buf)); |
| 1609 | eassert (BUF_INTERVALS (buffer)->up_obj == 1); | 1615 | buffer_get_intervals (buffer)->position = BUF_BEG (buffer); |
| 1610 | return; | 1616 | eassert (buffer_get_intervals (buffer)->up_obj == 1); |
| 1611 | } | 1617 | return; |
| 1612 | else if (NULL_INTERVAL_P (tree)) | 1618 | } |
| 1613 | { /* Create an interval tree in which to place a copy | 1619 | else if (!tree) |
| 1620 | { | ||
| 1621 | /* Create an interval tree in which to place a copy | ||
| 1614 | of the intervals of the inserted string. */ | 1622 | of the intervals of the inserted string. */ |
| 1615 | Lisp_Object buf; | 1623 | Lisp_Object buf; |
| 1624 | |||
| 1616 | XSETBUFFER (buf, buffer); | 1625 | XSETBUFFER (buf, buffer); |
| 1617 | tree = create_root_interval (buf); | 1626 | tree = create_root_interval (buf); |
| 1618 | } | 1627 | } |
| 1619 | /* Paranoia -- the text has already been added, so | 1628 | /* Paranoia -- the text has already been added, so |
| 1620 | this buffer should be of non-zero length. */ | 1629 | this buffer should be of non-zero length. */ |
| 1621 | eassert (TOTAL_LENGTH (tree) > 0); | 1630 | eassert (TOTAL_LENGTH (tree) > 0); |
| 1622 | 1631 | ||
| 1623 | this = under = find_interval (tree, position); | 1632 | this = under = find_interval (tree, position); |
| 1624 | eassert (!NULL_INTERVAL_P (under)); | 1633 | eassert (under); |
| 1625 | over = find_interval (source, interval_start_pos (source)); | 1634 | over = find_interval (source, interval_start_pos (source)); |
| 1626 | 1635 | ||
| 1627 | /* Here for insertion in the middle of an interval. | 1636 | /* Here for insertion in the middle of an interval. |
| @@ -1663,7 +1672,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1663 | have already been copied into target intervals. | 1672 | have already been copied into target intervals. |
| 1664 | UNDER is the next interval in the target. */ | 1673 | UNDER is the next interval in the target. */ |
| 1665 | over_used = 0; | 1674 | over_used = 0; |
| 1666 | while (! NULL_INTERVAL_P (over)) | 1675 | while (over) |
| 1667 | { | 1676 | { |
| 1668 | /* If UNDER is longer than OVER, split it. */ | 1677 | /* If UNDER is longer than OVER, split it. */ |
| 1669 | if (LENGTH (over) - over_used < LENGTH (under)) | 1678 | if (LENGTH (over) - over_used < LENGTH (under)) |
| @@ -1696,9 +1705,7 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1696 | under = next_interval (this); | 1705 | under = next_interval (this); |
| 1697 | } | 1706 | } |
| 1698 | 1707 | ||
| 1699 | if (! NULL_INTERVAL_P (BUF_INTERVALS (buffer))) | 1708 | buffer_balance_intervals (buffer); |
| 1700 | BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer)); | ||
| 1701 | return; | ||
| 1702 | } | 1709 | } |
| 1703 | 1710 | ||
| 1704 | /* Get the value of property PROP from PLIST, | 1711 | /* Get the value of property PROP from PLIST, |
| @@ -1847,7 +1854,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1847 | int have_overlays; | 1854 | int have_overlays; |
| 1848 | ptrdiff_t original_position; | 1855 | ptrdiff_t original_position; |
| 1849 | 1856 | ||
| 1850 | BVAR (current_buffer, point_before_scroll) = Qnil; | 1857 | BSET (current_buffer, point_before_scroll, Qnil); |
| 1851 | 1858 | ||
| 1852 | if (charpos == PT) | 1859 | if (charpos == PT) |
| 1853 | return; | 1860 | return; |
| @@ -1860,12 +1867,11 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1860 | whether or not there are intervals in the buffer. */ | 1867 | whether or not there are intervals in the buffer. */ |
| 1861 | eassert (charpos <= ZV && charpos >= BEGV); | 1868 | eassert (charpos <= ZV && charpos >= BEGV); |
| 1862 | 1869 | ||
| 1863 | have_overlays = (current_buffer->overlays_before | 1870 | have_overlays = buffer_has_overlays (); |
| 1864 | || current_buffer->overlays_after); | ||
| 1865 | 1871 | ||
| 1866 | /* If we have no text properties and overlays, | 1872 | /* If we have no text properties and overlays, |
| 1867 | then we can do it quickly. */ | 1873 | then we can do it quickly. */ |
| 1868 | if (NULL_INTERVAL_P (BUF_INTERVALS (current_buffer)) && ! have_overlays) | 1874 | if (!buffer_get_intervals (current_buffer) && ! have_overlays) |
| 1869 | { | 1875 | { |
| 1870 | temp_set_point_both (current_buffer, charpos, bytepos); | 1876 | temp_set_point_both (current_buffer, charpos, bytepos); |
| 1871 | return; | 1877 | return; |
| @@ -1874,7 +1880,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1874 | /* Set TO to the interval containing the char after CHARPOS, | 1880 | /* Set TO to the interval containing the char after CHARPOS, |
| 1875 | and TOPREV to the interval containing the char before CHARPOS. | 1881 | and TOPREV to the interval containing the char before CHARPOS. |
| 1876 | Either one may be null. They may be equal. */ | 1882 | Either one may be null. They may be equal. */ |
| 1877 | to = find_interval (BUF_INTERVALS (current_buffer), charpos); | 1883 | to = find_interval (buffer_get_intervals (current_buffer), charpos); |
| 1878 | if (charpos == BEGV) | 1884 | if (charpos == BEGV) |
| 1879 | toprev = 0; | 1885 | toprev = 0; |
| 1880 | else if (to && to->position == charpos) | 1886 | else if (to && to->position == charpos) |
| @@ -1888,7 +1894,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1888 | and FROMPREV to the interval containing the char before PT. | 1894 | and FROMPREV to the interval containing the char before PT. |
| 1889 | Either one may be null. They may be equal. */ | 1895 | Either one may be null. They may be equal. */ |
| 1890 | /* We could cache this and save time. */ | 1896 | /* We could cache this and save time. */ |
| 1891 | from = find_interval (BUF_INTERVALS (current_buffer), buffer_point); | 1897 | from = find_interval (buffer_get_intervals (current_buffer), buffer_point); |
| 1892 | if (buffer_point == BEGV) | 1898 | if (buffer_point == BEGV) |
| 1893 | fromprev = 0; | 1899 | fromprev = 0; |
| 1894 | else if (from && from->position == PT) | 1900 | else if (from && from->position == PT) |
| @@ -1912,7 +1918,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1912 | with the same intangible property value, | 1918 | with the same intangible property value, |
| 1913 | move forward or backward until a change in that property. */ | 1919 | move forward or backward until a change in that property. */ |
| 1914 | if (NILP (Vinhibit_point_motion_hooks) | 1920 | if (NILP (Vinhibit_point_motion_hooks) |
| 1915 | && ((! NULL_INTERVAL_P (to) && ! NULL_INTERVAL_P (toprev)) | 1921 | && ((to && toprev) |
| 1916 | || have_overlays) | 1922 | || have_overlays) |
| 1917 | /* Intangibility never stops us from positioning at the beginning | 1923 | /* Intangibility never stops us from positioning at the beginning |
| 1918 | or end of the buffer, so don't bother checking in that case. */ | 1924 | or end of the buffer, so don't bother checking in that case. */ |
| @@ -1994,7 +2000,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1994 | /* Set TO to the interval containing the char after CHARPOS, | 2000 | /* Set TO to the interval containing the char after CHARPOS, |
| 1995 | and TOPREV to the interval containing the char before CHARPOS. | 2001 | and TOPREV to the interval containing the char before CHARPOS. |
| 1996 | Either one may be null. They may be equal. */ | 2002 | Either one may be null. They may be equal. */ |
| 1997 | to = find_interval (BUF_INTERVALS (current_buffer), charpos); | 2003 | to = find_interval (buffer_get_intervals (current_buffer), charpos); |
| 1998 | if (charpos == BEGV) | 2004 | if (charpos == BEGV) |
| 1999 | toprev = 0; | 2005 | toprev = 0; |
| 2000 | else if (to && to->position == charpos) | 2006 | else if (to && to->position == charpos) |
| @@ -2127,15 +2133,15 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val, | |||
| 2127 | INTERVAL i, prev, next; | 2133 | INTERVAL i, prev, next; |
| 2128 | 2134 | ||
| 2129 | if (NILP (object)) | 2135 | if (NILP (object)) |
| 2130 | i = find_interval (BUF_INTERVALS (current_buffer), pos); | 2136 | i = find_interval (buffer_get_intervals (current_buffer), pos); |
| 2131 | else if (BUFFERP (object)) | 2137 | else if (BUFFERP (object)) |
| 2132 | i = find_interval (BUF_INTERVALS (XBUFFER (object)), pos); | 2138 | i = find_interval (buffer_get_intervals (XBUFFER (object)), pos); |
| 2133 | else if (STRINGP (object)) | 2139 | else if (STRINGP (object)) |
| 2134 | i = find_interval (STRING_INTERVALS (object), pos); | 2140 | i = find_interval (string_get_intervals (object), pos); |
| 2135 | else | 2141 | else |
| 2136 | abort (); | 2142 | abort (); |
| 2137 | 2143 | ||
| 2138 | if (NULL_INTERVAL_P (i) || (i->position + LENGTH (i) <= pos)) | 2144 | if (!i || (i->position + LENGTH (i) <= pos)) |
| 2139 | return 0; | 2145 | return 0; |
| 2140 | *val = textget (i->plist, prop); | 2146 | *val = textget (i->plist, prop); |
| 2141 | if (NILP (*val)) | 2147 | if (NILP (*val)) |
| @@ -2143,14 +2149,13 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val, | |||
| 2143 | 2149 | ||
| 2144 | next = i; /* remember it in advance */ | 2150 | next = i; /* remember it in advance */ |
| 2145 | prev = previous_interval (i); | 2151 | prev = previous_interval (i); |
| 2146 | while (! NULL_INTERVAL_P (prev) | 2152 | while (prev |
| 2147 | && EQ (*val, textget (prev->plist, prop))) | 2153 | && EQ (*val, textget (prev->plist, prop))) |
| 2148 | i = prev, prev = previous_interval (prev); | 2154 | i = prev, prev = previous_interval (prev); |
| 2149 | *start = i->position; | 2155 | *start = i->position; |
| 2150 | 2156 | ||
| 2151 | next = next_interval (i); | 2157 | next = next_interval (i); |
| 2152 | while (! NULL_INTERVAL_P (next) | 2158 | while (next && EQ (*val, textget (next->plist, prop))) |
| 2153 | && EQ (*val, textget (next->plist, prop))) | ||
| 2154 | i = next, next = next_interval (next); | 2159 | i = next, next = next_interval (next); |
| 2155 | *end = i->position + LENGTH (i); | 2160 | *end = i->position + LENGTH (i); |
| 2156 | 2161 | ||
| @@ -2221,22 +2226,22 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length) | |||
| 2221 | register INTERVAL i, new, t; | 2226 | register INTERVAL i, new, t; |
| 2222 | register ptrdiff_t got, prevlen; | 2227 | register ptrdiff_t got, prevlen; |
| 2223 | 2228 | ||
| 2224 | if (NULL_INTERVAL_P (tree) || length <= 0) | 2229 | if (!tree || length <= 0) |
| 2225 | return NULL_INTERVAL; | 2230 | return NULL; |
| 2226 | 2231 | ||
| 2227 | i = find_interval (tree, start); | 2232 | i = find_interval (tree, start); |
| 2228 | eassert (!NULL_INTERVAL_P (i) && LENGTH (i) > 0); | 2233 | eassert (i && LENGTH (i) > 0); |
| 2229 | 2234 | ||
| 2230 | /* If there is only one interval and it's the default, return nil. */ | 2235 | /* If there is only one interval and it's the default, return nil. */ |
| 2231 | if ((start - i->position + 1 + length) < LENGTH (i) | 2236 | if ((start - i->position + 1 + length) < LENGTH (i) |
| 2232 | && DEFAULT_INTERVAL_P (i)) | 2237 | && DEFAULT_INTERVAL_P (i)) |
| 2233 | return NULL_INTERVAL; | 2238 | return NULL; |
| 2234 | 2239 | ||
| 2235 | new = make_interval (); | 2240 | new = make_interval (); |
| 2236 | new->position = 0; | 2241 | new->position = 0; |
| 2237 | got = (LENGTH (i) - (start - i->position)); | 2242 | got = (LENGTH (i) - (start - i->position)); |
| 2238 | new->total_length = length; | 2243 | new->total_length = length; |
| 2239 | CHECK_TOTAL_LENGTH (new); | 2244 | eassert (0 <= TOTAL_LENGTH (new)); |
| 2240 | copy_properties (i, new); | 2245 | copy_properties (i, new); |
| 2241 | 2246 | ||
| 2242 | t = new; | 2247 | t = new; |
| @@ -2259,13 +2264,13 @@ void | |||
| 2259 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, | 2264 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, |
| 2260 | ptrdiff_t position, ptrdiff_t length) | 2265 | ptrdiff_t position, ptrdiff_t length) |
| 2261 | { | 2266 | { |
| 2262 | INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer), | 2267 | INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer), |
| 2263 | position, length); | 2268 | position, length); |
| 2264 | if (NULL_INTERVAL_P (interval_copy)) | 2269 | if (!interval_copy) |
| 2265 | return; | 2270 | return; |
| 2266 | 2271 | ||
| 2267 | SET_INTERVAL_OBJECT (interval_copy, string); | 2272 | interval_set_object (interval_copy, string); |
| 2268 | STRING_SET_INTERVALS (string, interval_copy); | 2273 | string_set_intervals (string, interval_copy); |
| 2269 | } | 2274 | } |
| 2270 | 2275 | ||
| 2271 | /* Return 1 if strings S1 and S2 have identical properties; 0 otherwise. | 2276 | /* Return 1 if strings S1 and S2 have identical properties; 0 otherwise. |
| @@ -2278,8 +2283,8 @@ compare_string_intervals (Lisp_Object s1, Lisp_Object s2) | |||
| 2278 | ptrdiff_t pos = 0; | 2283 | ptrdiff_t pos = 0; |
| 2279 | ptrdiff_t end = SCHARS (s1); | 2284 | ptrdiff_t end = SCHARS (s1); |
| 2280 | 2285 | ||
| 2281 | i1 = find_interval (STRING_INTERVALS (s1), 0); | 2286 | i1 = find_interval (string_get_intervals (s1), 0); |
| 2282 | i2 = find_interval (STRING_INTERVALS (s2), 0); | 2287 | i2 = find_interval (string_get_intervals (s2), 0); |
| 2283 | 2288 | ||
| 2284 | while (pos < end) | 2289 | while (pos < end) |
| 2285 | { | 2290 | { |
| @@ -2319,7 +2324,7 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2319 | i->total_length = end - start; | 2324 | i->total_length = end - start; |
| 2320 | else | 2325 | else |
| 2321 | i->total_length = end_byte - start_byte; | 2326 | i->total_length = end_byte - start_byte; |
| 2322 | CHECK_TOTAL_LENGTH (i); | 2327 | eassert (0 <= TOTAL_LENGTH (i)); |
| 2323 | 2328 | ||
| 2324 | if (TOTAL_LENGTH (i) == 0) | 2329 | if (TOTAL_LENGTH (i) == 0) |
| 2325 | { | 2330 | { |
| @@ -2404,13 +2409,13 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2404 | { | 2409 | { |
| 2405 | if ((i)->left) | 2410 | if ((i)->left) |
| 2406 | { | 2411 | { |
| 2407 | (i)->plist = (i)->left->plist; | 2412 | interval_set_plist (i, i->left->plist); |
| 2408 | (i)->left->total_length = 0; | 2413 | (i)->left->total_length = 0; |
| 2409 | delete_interval ((i)->left); | 2414 | delete_interval ((i)->left); |
| 2410 | } | 2415 | } |
| 2411 | else | 2416 | else |
| 2412 | { | 2417 | { |
| 2413 | (i)->plist = (i)->right->plist; | 2418 | interval_set_plist (i, i->right->plist); |
| 2414 | (i)->right->total_length = 0; | 2419 | (i)->right->total_length = 0; |
| 2415 | delete_interval ((i)->right); | 2420 | delete_interval ((i)->right); |
| 2416 | } | 2421 | } |
| @@ -2424,7 +2429,8 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2424 | void | 2429 | void |
| 2425 | set_intervals_multibyte (int multi_flag) | 2430 | set_intervals_multibyte (int multi_flag) |
| 2426 | { | 2431 | { |
| 2427 | if (BUF_INTERVALS (current_buffer)) | 2432 | INTERVAL i = buffer_get_intervals (current_buffer); |
| 2428 | set_intervals_multibyte_1 (BUF_INTERVALS (current_buffer), multi_flag, | 2433 | |
| 2429 | BEG, BEG_BYTE, Z, Z_BYTE); | 2434 | if (i) |
| 2435 | set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE); | ||
| 2430 | } | 2436 | } |