diff options
| author | Joakim Verona | 2012-08-19 02:44:11 +0200 |
|---|---|---|
| committer | Joakim Verona | 2012-08-19 02:44:11 +0200 |
| commit | 5436d1df5e2ba0b4d4f72b03a1cd09b20403654b (patch) | |
| tree | 532faa27319b3bb199d414dc85e63a58246d30b0 /src/intervals.c | |
| parent | d02344322b0d2fea8dd9ad9dd0a6c70e058f967b (diff) | |
| parent | e757f1c6f393cf82057dbee0a4325b07f0fd55c4 (diff) | |
| download | emacs-5436d1df5e2ba0b4d4f72b03a1cd09b20403654b.tar.gz emacs-5436d1df5e2ba0b4d4f72b03a1cd09b20403654b.zip | |
upstream
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 229 |
1 files changed, 131 insertions, 98 deletions
diff --git a/src/intervals.c b/src/intervals.c index 09949bbbd45..0a85e20e5d9 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -59,10 +59,41 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 59 | static Lisp_Object merge_properties_sticky (Lisp_Object, Lisp_Object); | 59 | static Lisp_Object merge_properties_sticky (Lisp_Object, Lisp_Object); |
| 60 | static INTERVAL merge_interval_right (INTERVAL); | 60 | static INTERVAL merge_interval_right (INTERVAL); |
| 61 | static INTERVAL reproduce_tree (INTERVAL, INTERVAL); | 61 | static INTERVAL reproduce_tree (INTERVAL, INTERVAL); |
| 62 | static INTERVAL reproduce_tree_obj (INTERVAL, Lisp_Object); | ||
| 63 | 62 | ||
| 64 | /* Utility functions for intervals. */ | 63 | /* Utility functions for intervals. */ |
| 65 | 64 | ||
| 65 | /* Use these functions to set Lisp_Object | ||
| 66 | or pointer slots of struct interval. */ | ||
| 67 | |||
| 68 | static inline void | ||
| 69 | set_interval_object (INTERVAL i, Lisp_Object obj) | ||
| 70 | { | ||
| 71 | eassert (BUFFERP (obj) || STRINGP (obj)); | ||
| 72 | i->up_obj = 1; | ||
| 73 | i->up.obj = obj; | ||
| 74 | } | ||
| 75 | |||
| 76 | static inline void | ||
| 77 | set_interval_left (INTERVAL i, INTERVAL left) | ||
| 78 | { | ||
| 79 | i->left = left; | ||
| 80 | } | ||
| 81 | |||
| 82 | static inline void | ||
| 83 | set_interval_right (INTERVAL i, INTERVAL right) | ||
| 84 | { | ||
| 85 | i->right = right; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Make the parent of D be whatever the parent of S is, regardless | ||
| 89 | of the type. This is used when balancing an interval tree. */ | ||
| 90 | |||
| 91 | static inline void | ||
| 92 | copy_interval_parent (INTERVAL d, INTERVAL s) | ||
| 93 | { | ||
| 94 | d->up = s->up; | ||
| 95 | d->up_obj = s->up_obj; | ||
| 96 | } | ||
| 66 | 97 | ||
| 67 | /* Create the root interval of some object, a buffer or string. */ | 98 | /* Create the root interval of some object, a buffer or string. */ |
| 68 | 99 | ||
| @@ -80,18 +111,18 @@ create_root_interval (Lisp_Object parent) | |||
| 80 | new->total_length = (BUF_Z (XBUFFER (parent)) | 111 | new->total_length = (BUF_Z (XBUFFER (parent)) |
| 81 | - BUF_BEG (XBUFFER (parent))); | 112 | - BUF_BEG (XBUFFER (parent))); |
| 82 | eassert (0 <= TOTAL_LENGTH (new)); | 113 | eassert (0 <= TOTAL_LENGTH (new)); |
| 83 | buffer_set_intervals (XBUFFER (parent), new); | 114 | set_buffer_intervals (XBUFFER (parent), new); |
| 84 | new->position = BEG; | 115 | new->position = BEG; |
| 85 | } | 116 | } |
| 86 | else if (STRINGP (parent)) | 117 | else if (STRINGP (parent)) |
| 87 | { | 118 | { |
| 88 | new->total_length = SCHARS (parent); | 119 | new->total_length = SCHARS (parent); |
| 89 | eassert (0 <= TOTAL_LENGTH (new)); | 120 | eassert (0 <= TOTAL_LENGTH (new)); |
| 90 | string_set_intervals (parent, new); | 121 | set_string_intervals (parent, new); |
| 91 | new->position = 0; | 122 | new->position = 0; |
| 92 | } | 123 | } |
| 93 | 124 | ||
| 94 | interval_set_object (new, parent); | 125 | set_interval_object (new, parent); |
| 95 | 126 | ||
| 96 | return new; | 127 | return new; |
| 97 | } | 128 | } |
| @@ -105,7 +136,7 @@ copy_properties (register INTERVAL source, register INTERVAL target) | |||
| 105 | return; | 136 | return; |
| 106 | 137 | ||
| 107 | COPY_INTERVAL_CACHE (source, target); | 138 | COPY_INTERVAL_CACHE (source, target); |
| 108 | interval_set_plist (target, Fcopy_sequence (source->plist)); | 139 | set_interval_plist (target, Fcopy_sequence (source->plist)); |
| 109 | } | 140 | } |
| 110 | 141 | ||
| 111 | /* Merge the properties of interval SOURCE into the properties | 142 | /* Merge the properties of interval SOURCE into the properties |
| @@ -141,7 +172,7 @@ merge_properties (register INTERVAL source, register INTERVAL target) | |||
| 141 | if (NILP (val)) | 172 | if (NILP (val)) |
| 142 | { | 173 | { |
| 143 | val = XCAR (o); | 174 | val = XCAR (o); |
| 144 | interval_set_plist (target, Fcons (sym, Fcons (val, target->plist))); | 175 | set_interval_plist (target, Fcons (sym, Fcons (val, target->plist))); |
| 145 | } | 176 | } |
| 146 | o = XCDR (o); | 177 | o = XCDR (o); |
| 147 | } | 178 | } |
| @@ -323,21 +354,21 @@ rotate_right (INTERVAL interval) | |||
| 323 | if (! ROOT_INTERVAL_P (interval)) | 354 | if (! ROOT_INTERVAL_P (interval)) |
| 324 | { | 355 | { |
| 325 | if (AM_LEFT_CHILD (interval)) | 356 | if (AM_LEFT_CHILD (interval)) |
| 326 | interval_set_left (INTERVAL_PARENT (interval), B); | 357 | set_interval_left (INTERVAL_PARENT (interval), B); |
| 327 | else | 358 | else |
| 328 | interval_set_right (INTERVAL_PARENT (interval), B); | 359 | set_interval_right (INTERVAL_PARENT (interval), B); |
| 329 | } | 360 | } |
| 330 | interval_copy_parent (B, interval); | 361 | copy_interval_parent (B, interval); |
| 331 | 362 | ||
| 332 | /* Make B the parent of A */ | 363 | /* Make B the parent of A */ |
| 333 | i = B->right; | 364 | i = B->right; |
| 334 | interval_set_right (B, interval); | 365 | set_interval_right (B, interval); |
| 335 | interval_set_parent (interval, B); | 366 | set_interval_parent (interval, B); |
| 336 | 367 | ||
| 337 | /* Make A point to c */ | 368 | /* Make A point to c */ |
| 338 | interval_set_left (interval, i); | 369 | set_interval_left (interval, i); |
| 339 | if (i) | 370 | if (i) |
| 340 | interval_set_parent (i, interval); | 371 | set_interval_parent (i, interval); |
| 341 | 372 | ||
| 342 | /* A's total length is decreased by the length of B and its left child. */ | 373 | /* A's total length is decreased by the length of B and its left child. */ |
| 343 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); | 374 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); |
| @@ -370,21 +401,21 @@ rotate_left (INTERVAL interval) | |||
| 370 | if (! ROOT_INTERVAL_P (interval)) | 401 | if (! ROOT_INTERVAL_P (interval)) |
| 371 | { | 402 | { |
| 372 | if (AM_LEFT_CHILD (interval)) | 403 | if (AM_LEFT_CHILD (interval)) |
| 373 | interval_set_left (INTERVAL_PARENT (interval), B); | 404 | set_interval_left (INTERVAL_PARENT (interval), B); |
| 374 | else | 405 | else |
| 375 | interval_set_right (INTERVAL_PARENT (interval), B); | 406 | set_interval_right (INTERVAL_PARENT (interval), B); |
| 376 | } | 407 | } |
| 377 | interval_copy_parent (B, interval); | 408 | copy_interval_parent (B, interval); |
| 378 | 409 | ||
| 379 | /* Make B the parent of A */ | 410 | /* Make B the parent of A */ |
| 380 | i = B->left; | 411 | i = B->left; |
| 381 | interval_set_left (B, interval); | 412 | set_interval_left (B, interval); |
| 382 | interval_set_parent (interval, B); | 413 | set_interval_parent (interval, B); |
| 383 | 414 | ||
| 384 | /* Make A point to c */ | 415 | /* Make A point to c */ |
| 385 | interval_set_right (interval, i); | 416 | set_interval_right (interval, i); |
| 386 | if (i) | 417 | if (i) |
| 387 | interval_set_parent (i, interval); | 418 | set_interval_parent (i, interval); |
| 388 | 419 | ||
| 389 | /* A's total length is decreased by the length of B and its right child. */ | 420 | /* A's total length is decreased by the length of B and its right child. */ |
| 390 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); | 421 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); |
| @@ -456,9 +487,9 @@ balance_possible_root_interval (register INTERVAL interval) | |||
| 456 | if (have_parent) | 487 | if (have_parent) |
| 457 | { | 488 | { |
| 458 | if (BUFFERP (parent)) | 489 | if (BUFFERP (parent)) |
| 459 | buffer_set_intervals (XBUFFER (parent), interval); | 490 | set_buffer_intervals (XBUFFER (parent), interval); |
| 460 | else if (STRINGP (parent)) | 491 | else if (STRINGP (parent)) |
| 461 | string_set_intervals (parent, interval); | 492 | set_string_intervals (parent, interval); |
| 462 | } | 493 | } |
| 463 | 494 | ||
| 464 | return interval; | 495 | return interval; |
| @@ -494,9 +525,9 @@ buffer_balance_intervals (struct buffer *b) | |||
| 494 | INTERVAL i; | 525 | INTERVAL i; |
| 495 | 526 | ||
| 496 | eassert (b != NULL); | 527 | eassert (b != NULL); |
| 497 | i = buffer_get_intervals (b); | 528 | i = buffer_intervals (b); |
| 498 | if (i) | 529 | if (i) |
| 499 | buffer_set_intervals (b, balance_an_interval (i)); | 530 | set_buffer_intervals (b, balance_an_interval (i)); |
| 500 | } | 531 | } |
| 501 | 532 | ||
| 502 | /* Split INTERVAL into two pieces, starting the second piece at | 533 | /* Split INTERVAL into two pieces, starting the second piece at |
| @@ -520,20 +551,20 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) | |||
| 520 | ptrdiff_t new_length = LENGTH (interval) - offset; | 551 | ptrdiff_t new_length = LENGTH (interval) - offset; |
| 521 | 552 | ||
| 522 | new->position = position + offset; | 553 | new->position = position + offset; |
| 523 | interval_set_parent (new, interval); | 554 | set_interval_parent (new, interval); |
| 524 | 555 | ||
| 525 | if (NULL_RIGHT_CHILD (interval)) | 556 | if (NULL_RIGHT_CHILD (interval)) |
| 526 | { | 557 | { |
| 527 | interval_set_right (interval, new); | 558 | set_interval_right (interval, new); |
| 528 | new->total_length = new_length; | 559 | new->total_length = new_length; |
| 529 | eassert (0 <= TOTAL_LENGTH (new)); | 560 | eassert (0 <= TOTAL_LENGTH (new)); |
| 530 | } | 561 | } |
| 531 | else | 562 | else |
| 532 | { | 563 | { |
| 533 | /* Insert the new node between INTERVAL and its right child. */ | 564 | /* Insert the new node between INTERVAL and its right child. */ |
| 534 | interval_set_right (new, interval->right); | 565 | set_interval_right (new, interval->right); |
| 535 | interval_set_parent (interval->right, new); | 566 | set_interval_parent (interval->right, new); |
| 536 | interval_set_right (interval, new); | 567 | set_interval_right (interval, new); |
| 537 | new->total_length = new_length + new->right->total_length; | 568 | new->total_length = new_length + new->right->total_length; |
| 538 | eassert (0 <= TOTAL_LENGTH (new)); | 569 | eassert (0 <= TOTAL_LENGTH (new)); |
| 539 | balance_an_interval (new); | 570 | balance_an_interval (new); |
| @@ -565,20 +596,20 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) | |||
| 565 | 596 | ||
| 566 | new->position = interval->position; | 597 | new->position = interval->position; |
| 567 | interval->position = interval->position + offset; | 598 | interval->position = interval->position + offset; |
| 568 | interval_set_parent (new, interval); | 599 | set_interval_parent (new, interval); |
| 569 | 600 | ||
| 570 | if (NULL_LEFT_CHILD (interval)) | 601 | if (NULL_LEFT_CHILD (interval)) |
| 571 | { | 602 | { |
| 572 | interval_set_left (interval, new); | 603 | set_interval_left (interval, new); |
| 573 | new->total_length = new_length; | 604 | new->total_length = new_length; |
| 574 | eassert (0 <= TOTAL_LENGTH (new)); | 605 | eassert (0 <= TOTAL_LENGTH (new)); |
| 575 | } | 606 | } |
| 576 | else | 607 | else |
| 577 | { | 608 | { |
| 578 | /* Insert the new node between INTERVAL and its left child. */ | 609 | /* Insert the new node between INTERVAL and its left child. */ |
| 579 | interval_set_left (new, interval->left); | 610 | set_interval_left (new, interval->left); |
| 580 | interval_set_parent (new->left, new); | 611 | set_interval_parent (new->left, new); |
| 581 | interval_set_left (interval, new); | 612 | set_interval_left (interval, new); |
| 582 | new->total_length = new_length + new->left->total_length; | 613 | new->total_length = new_length + new->left->total_length; |
| 583 | eassert (0 <= TOTAL_LENGTH (new)); | 614 | eassert (0 <= TOTAL_LENGTH (new)); |
| 584 | balance_an_interval (new); | 615 | balance_an_interval (new); |
| @@ -953,20 +984,20 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 953 | RESET_INTERVAL (&newi); | 984 | RESET_INTERVAL (&newi); |
| 954 | pleft = prev ? prev->plist : Qnil; | 985 | pleft = prev ? prev->plist : Qnil; |
| 955 | pright = i ? i->plist : Qnil; | 986 | pright = i ? i->plist : Qnil; |
| 956 | interval_set_plist (&newi, merge_properties_sticky (pleft, pright)); | 987 | set_interval_plist (&newi, merge_properties_sticky (pleft, pright)); |
| 957 | 988 | ||
| 958 | if (! prev) /* i.e. position == BEG */ | 989 | if (! prev) /* i.e. position == BEG */ |
| 959 | { | 990 | { |
| 960 | if (! intervals_equal (i, &newi)) | 991 | if (! intervals_equal (i, &newi)) |
| 961 | { | 992 | { |
| 962 | i = split_interval_left (i, length); | 993 | i = split_interval_left (i, length); |
| 963 | interval_set_plist (i, newi.plist); | 994 | set_interval_plist (i, newi.plist); |
| 964 | } | 995 | } |
| 965 | } | 996 | } |
| 966 | else if (! intervals_equal (prev, &newi)) | 997 | else if (! intervals_equal (prev, &newi)) |
| 967 | { | 998 | { |
| 968 | prev = split_interval_right (prev, position - prev->position); | 999 | prev = split_interval_right (prev, position - prev->position); |
| 969 | interval_set_plist (prev, newi.plist); | 1000 | set_interval_plist (prev, newi.plist); |
| 970 | if (i && intervals_equal (prev, i)) | 1001 | if (i && intervals_equal (prev, i)) |
| 971 | merge_interval_right (prev); | 1002 | merge_interval_right (prev); |
| 972 | } | 1003 | } |
| @@ -1191,8 +1222,8 @@ delete_node (register INTERVAL i) | |||
| 1191 | this->total_length += migrate_amt; | 1222 | this->total_length += migrate_amt; |
| 1192 | } | 1223 | } |
| 1193 | eassert (0 <= TOTAL_LENGTH (this)); | 1224 | eassert (0 <= TOTAL_LENGTH (this)); |
| 1194 | interval_set_left (this, migrate); | 1225 | set_interval_left (this, migrate); |
| 1195 | interval_set_parent (migrate, this); | 1226 | set_interval_parent (migrate, this); |
| 1196 | 1227 | ||
| 1197 | return i->right; | 1228 | return i->right; |
| 1198 | } | 1229 | } |
| @@ -1217,12 +1248,12 @@ delete_interval (register INTERVAL i) | |||
| 1217 | GET_INTERVAL_OBJECT (owner, i); | 1248 | GET_INTERVAL_OBJECT (owner, i); |
| 1218 | parent = delete_node (i); | 1249 | parent = delete_node (i); |
| 1219 | if (parent) | 1250 | if (parent) |
| 1220 | interval_set_object (parent, owner); | 1251 | set_interval_object (parent, owner); |
| 1221 | 1252 | ||
| 1222 | if (BUFFERP (owner)) | 1253 | if (BUFFERP (owner)) |
| 1223 | buffer_set_intervals (XBUFFER (owner), parent); | 1254 | set_buffer_intervals (XBUFFER (owner), parent); |
| 1224 | else if (STRINGP (owner)) | 1255 | else if (STRINGP (owner)) |
| 1225 | string_set_intervals (owner, parent); | 1256 | set_string_intervals (owner, parent); |
| 1226 | else | 1257 | else |
| 1227 | abort (); | 1258 | abort (); |
| 1228 | 1259 | ||
| @@ -1232,15 +1263,15 @@ delete_interval (register INTERVAL i) | |||
| 1232 | parent = INTERVAL_PARENT (i); | 1263 | parent = INTERVAL_PARENT (i); |
| 1233 | if (AM_LEFT_CHILD (i)) | 1264 | if (AM_LEFT_CHILD (i)) |
| 1234 | { | 1265 | { |
| 1235 | interval_set_left (parent, delete_node (i)); | 1266 | set_interval_left (parent, delete_node (i)); |
| 1236 | if (parent->left) | 1267 | if (parent->left) |
| 1237 | interval_set_parent (parent->left, parent); | 1268 | set_interval_parent (parent->left, parent); |
| 1238 | } | 1269 | } |
| 1239 | else | 1270 | else |
| 1240 | { | 1271 | { |
| 1241 | interval_set_right (parent, delete_node (i)); | 1272 | set_interval_right (parent, delete_node (i)); |
| 1242 | if (parent->right) | 1273 | if (parent->right) |
| 1243 | interval_set_parent (parent->right, parent); | 1274 | set_interval_parent (parent->right, parent); |
| 1244 | } | 1275 | } |
| 1245 | } | 1276 | } |
| 1246 | 1277 | ||
| @@ -1321,8 +1352,8 @@ static void | |||
| 1321 | adjust_intervals_for_deletion (struct buffer *buffer, | 1352 | adjust_intervals_for_deletion (struct buffer *buffer, |
| 1322 | ptrdiff_t start, ptrdiff_t length) | 1353 | ptrdiff_t start, ptrdiff_t length) |
| 1323 | { | 1354 | { |
| 1324 | register ptrdiff_t left_to_delete = length; | 1355 | ptrdiff_t left_to_delete = length; |
| 1325 | register INTERVAL tree = buffer_get_intervals (buffer); | 1356 | INTERVAL tree = buffer_intervals (buffer); |
| 1326 | Lisp_Object parent; | 1357 | Lisp_Object parent; |
| 1327 | ptrdiff_t offset; | 1358 | ptrdiff_t offset; |
| 1328 | 1359 | ||
| @@ -1337,7 +1368,7 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1337 | 1368 | ||
| 1338 | if (length == TOTAL_LENGTH (tree)) | 1369 | if (length == TOTAL_LENGTH (tree)) |
| 1339 | { | 1370 | { |
| 1340 | buffer_set_intervals (buffer, NULL); | 1371 | set_buffer_intervals (buffer, NULL); |
| 1341 | return; | 1372 | return; |
| 1342 | } | 1373 | } |
| 1343 | 1374 | ||
| @@ -1354,10 +1385,10 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1354 | { | 1385 | { |
| 1355 | left_to_delete -= interval_deletion_adjustment (tree, start - offset, | 1386 | left_to_delete -= interval_deletion_adjustment (tree, start - offset, |
| 1356 | left_to_delete); | 1387 | left_to_delete); |
| 1357 | tree = buffer_get_intervals (buffer); | 1388 | tree = buffer_intervals (buffer); |
| 1358 | if (left_to_delete == tree->total_length) | 1389 | if (left_to_delete == tree->total_length) |
| 1359 | { | 1390 | { |
| 1360 | buffer_set_intervals (buffer, NULL); | 1391 | set_buffer_intervals (buffer, NULL); |
| 1361 | return; | 1392 | return; |
| 1362 | } | 1393 | } |
| 1363 | } | 1394 | } |
| @@ -1371,11 +1402,11 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1371 | void | 1402 | void |
| 1372 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) | 1403 | offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length) |
| 1373 | { | 1404 | { |
| 1374 | if (!buffer_get_intervals (buffer) || length == 0) | 1405 | if (!buffer_intervals (buffer) || length == 0) |
| 1375 | return; | 1406 | return; |
| 1376 | 1407 | ||
| 1377 | if (length > 0) | 1408 | if (length > 0) |
| 1378 | adjust_intervals_for_insertion (buffer_get_intervals (buffer), | 1409 | adjust_intervals_for_insertion (buffer_intervals (buffer), |
| 1379 | start, length); | 1410 | start, length); |
| 1380 | else | 1411 | else |
| 1381 | { | 1412 | { |
| @@ -1498,6 +1529,26 @@ merge_interval_left (register INTERVAL i) | |||
| 1498 | abort (); | 1529 | abort (); |
| 1499 | } | 1530 | } |
| 1500 | 1531 | ||
| 1532 | /* Create a copy of SOURCE but with the default value of UP. */ | ||
| 1533 | |||
| 1534 | static INTERVAL | ||
| 1535 | reproduce_interval (INTERVAL source) | ||
| 1536 | { | ||
| 1537 | register INTERVAL target = make_interval (); | ||
| 1538 | |||
| 1539 | target->total_length = source->total_length; | ||
| 1540 | target->position = source->position; | ||
| 1541 | |||
| 1542 | copy_properties (source, target); | ||
| 1543 | |||
| 1544 | if (! NULL_LEFT_CHILD (source)) | ||
| 1545 | set_interval_left (target, reproduce_tree (source->left, target)); | ||
| 1546 | if (! NULL_RIGHT_CHILD (source)) | ||
| 1547 | set_interval_right (target, reproduce_tree (source->right, target)); | ||
| 1548 | |||
| 1549 | return target; | ||
| 1550 | } | ||
| 1551 | |||
| 1501 | /* Make an exact copy of interval tree SOURCE which descends from | 1552 | /* Make an exact copy of interval tree SOURCE which descends from |
| 1502 | PARENT. This is done by recursing through SOURCE, copying | 1553 | PARENT. This is done by recursing through SOURCE, copying |
| 1503 | the current interval and its properties, and then adjusting | 1554 | the current interval and its properties, and then adjusting |
| @@ -1506,33 +1557,17 @@ merge_interval_left (register INTERVAL i) | |||
| 1506 | static INTERVAL | 1557 | static INTERVAL |
| 1507 | reproduce_tree (INTERVAL source, INTERVAL parent) | 1558 | reproduce_tree (INTERVAL source, INTERVAL parent) |
| 1508 | { | 1559 | { |
| 1509 | register INTERVAL t = make_interval (); | 1560 | INTERVAL target = reproduce_interval (source); |
| 1510 | 1561 | set_interval_parent (target, parent); | |
| 1511 | memcpy (t, source, sizeof *t); | 1562 | return target; |
| 1512 | copy_properties (source, t); | ||
| 1513 | interval_set_parent (t, parent); | ||
| 1514 | if (! NULL_LEFT_CHILD (source)) | ||
| 1515 | interval_set_left (t, reproduce_tree (source->left, t)); | ||
| 1516 | if (! NULL_RIGHT_CHILD (source)) | ||
| 1517 | interval_set_right (t, reproduce_tree (source->right, t)); | ||
| 1518 | |||
| 1519 | return t; | ||
| 1520 | } | 1563 | } |
| 1521 | 1564 | ||
| 1522 | static INTERVAL | 1565 | static INTERVAL |
| 1523 | reproduce_tree_obj (INTERVAL source, Lisp_Object parent) | 1566 | reproduce_tree_obj (INTERVAL source, Lisp_Object parent) |
| 1524 | { | 1567 | { |
| 1525 | register INTERVAL t = make_interval (); | 1568 | INTERVAL target = reproduce_interval (source); |
| 1526 | 1569 | set_interval_object (target, parent); | |
| 1527 | memcpy (t, source, sizeof *t); | 1570 | return target; |
| 1528 | copy_properties (source, t); | ||
| 1529 | interval_set_object (t, parent); | ||
| 1530 | if (! NULL_LEFT_CHILD (source)) | ||
| 1531 | interval_set_left (t, reproduce_tree (source->left, t)); | ||
| 1532 | if (! NULL_RIGHT_CHILD (source)) | ||
| 1533 | interval_set_right (t, reproduce_tree (source->right, t)); | ||
| 1534 | |||
| 1535 | return t; | ||
| 1536 | } | 1571 | } |
| 1537 | 1572 | ||
| 1538 | /* Insert the intervals of SOURCE into BUFFER at POSITION. | 1573 | /* Insert the intervals of SOURCE into BUFFER at POSITION. |
| @@ -1577,12 +1612,10 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1577 | ptrdiff_t length, struct buffer *buffer, | 1612 | ptrdiff_t length, struct buffer *buffer, |
| 1578 | int inherit) | 1613 | int inherit) |
| 1579 | { | 1614 | { |
| 1580 | register INTERVAL under, over, this; | 1615 | INTERVAL tree = buffer_intervals (buffer); |
| 1581 | register INTERVAL tree; | 1616 | INTERVAL under, over, this; |
| 1582 | ptrdiff_t over_used; | 1617 | ptrdiff_t over_used; |
| 1583 | 1618 | ||
| 1584 | tree = buffer_get_intervals (buffer); | ||
| 1585 | |||
| 1586 | /* If the new text has no properties, then with inheritance it | 1619 | /* If the new text has no properties, then with inheritance it |
| 1587 | becomes part of whatever interval it was inserted into. | 1620 | becomes part of whatever interval it was inserted into. |
| 1588 | To prevent inheritance, we must clear out the properties | 1621 | To prevent inheritance, we must clear out the properties |
| @@ -1611,9 +1644,9 @@ graft_intervals_into_buffer (INTERVAL source, ptrdiff_t position, | |||
| 1611 | Lisp_Object buf; | 1644 | Lisp_Object buf; |
| 1612 | 1645 | ||
| 1613 | XSETBUFFER (buf, buffer); | 1646 | XSETBUFFER (buf, buffer); |
| 1614 | buffer_set_intervals (buffer, reproduce_tree_obj (source, buf)); | 1647 | set_buffer_intervals (buffer, reproduce_tree_obj (source, buf)); |
| 1615 | buffer_get_intervals (buffer)->position = BUF_BEG (buffer); | 1648 | buffer_intervals (buffer)->position = BUF_BEG (buffer); |
| 1616 | eassert (buffer_get_intervals (buffer)->up_obj == 1); | 1649 | eassert (buffer_intervals (buffer)->up_obj == 1); |
| 1617 | return; | 1650 | return; |
| 1618 | } | 1651 | } |
| 1619 | else if (!tree) | 1652 | else if (!tree) |
| @@ -1854,7 +1887,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1854 | int have_overlays; | 1887 | int have_overlays; |
| 1855 | ptrdiff_t original_position; | 1888 | ptrdiff_t original_position; |
| 1856 | 1889 | ||
| 1857 | BSET (current_buffer, point_before_scroll, Qnil); | 1890 | bset_point_before_scroll (current_buffer, Qnil); |
| 1858 | 1891 | ||
| 1859 | if (charpos == PT) | 1892 | if (charpos == PT) |
| 1860 | return; | 1893 | return; |
| @@ -1871,7 +1904,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1871 | 1904 | ||
| 1872 | /* If we have no text properties and overlays, | 1905 | /* If we have no text properties and overlays, |
| 1873 | then we can do it quickly. */ | 1906 | then we can do it quickly. */ |
| 1874 | if (!buffer_get_intervals (current_buffer) && ! have_overlays) | 1907 | if (!buffer_intervals (current_buffer) && ! have_overlays) |
| 1875 | { | 1908 | { |
| 1876 | temp_set_point_both (current_buffer, charpos, bytepos); | 1909 | temp_set_point_both (current_buffer, charpos, bytepos); |
| 1877 | return; | 1910 | return; |
| @@ -1880,7 +1913,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1880 | /* Set TO to the interval containing the char after CHARPOS, | 1913 | /* Set TO to the interval containing the char after CHARPOS, |
| 1881 | and TOPREV to the interval containing the char before CHARPOS. | 1914 | and TOPREV to the interval containing the char before CHARPOS. |
| 1882 | Either one may be null. They may be equal. */ | 1915 | Either one may be null. They may be equal. */ |
| 1883 | to = find_interval (buffer_get_intervals (current_buffer), charpos); | 1916 | to = find_interval (buffer_intervals (current_buffer), charpos); |
| 1884 | if (charpos == BEGV) | 1917 | if (charpos == BEGV) |
| 1885 | toprev = 0; | 1918 | toprev = 0; |
| 1886 | else if (to && to->position == charpos) | 1919 | else if (to && to->position == charpos) |
| @@ -1894,7 +1927,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 1894 | and FROMPREV to the interval containing the char before PT. | 1927 | and FROMPREV to the interval containing the char before PT. |
| 1895 | Either one may be null. They may be equal. */ | 1928 | Either one may be null. They may be equal. */ |
| 1896 | /* We could cache this and save time. */ | 1929 | /* We could cache this and save time. */ |
| 1897 | from = find_interval (buffer_get_intervals (current_buffer), buffer_point); | 1930 | from = find_interval (buffer_intervals (current_buffer), buffer_point); |
| 1898 | if (buffer_point == BEGV) | 1931 | if (buffer_point == BEGV) |
| 1899 | fromprev = 0; | 1932 | fromprev = 0; |
| 1900 | else if (from && from->position == PT) | 1933 | else if (from && from->position == PT) |
| @@ -2000,7 +2033,7 @@ set_point_both (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 2000 | /* Set TO to the interval containing the char after CHARPOS, | 2033 | /* Set TO to the interval containing the char after CHARPOS, |
| 2001 | and TOPREV to the interval containing the char before CHARPOS. | 2034 | and TOPREV to the interval containing the char before CHARPOS. |
| 2002 | Either one may be null. They may be equal. */ | 2035 | Either one may be null. They may be equal. */ |
| 2003 | to = find_interval (buffer_get_intervals (current_buffer), charpos); | 2036 | to = find_interval (buffer_intervals (current_buffer), charpos); |
| 2004 | if (charpos == BEGV) | 2037 | if (charpos == BEGV) |
| 2005 | toprev = 0; | 2038 | toprev = 0; |
| 2006 | else if (to && to->position == charpos) | 2039 | else if (to && to->position == charpos) |
| @@ -2133,11 +2166,11 @@ get_property_and_range (ptrdiff_t pos, Lisp_Object prop, Lisp_Object *val, | |||
| 2133 | INTERVAL i, prev, next; | 2166 | INTERVAL i, prev, next; |
| 2134 | 2167 | ||
| 2135 | if (NILP (object)) | 2168 | if (NILP (object)) |
| 2136 | i = find_interval (buffer_get_intervals (current_buffer), pos); | 2169 | i = find_interval (buffer_intervals (current_buffer), pos); |
| 2137 | else if (BUFFERP (object)) | 2170 | else if (BUFFERP (object)) |
| 2138 | i = find_interval (buffer_get_intervals (XBUFFER (object)), pos); | 2171 | i = find_interval (buffer_intervals (XBUFFER (object)), pos); |
| 2139 | else if (STRINGP (object)) | 2172 | else if (STRINGP (object)) |
| 2140 | i = find_interval (string_get_intervals (object), pos); | 2173 | i = find_interval (string_intervals (object), pos); |
| 2141 | else | 2174 | else |
| 2142 | abort (); | 2175 | abort (); |
| 2143 | 2176 | ||
| @@ -2264,13 +2297,13 @@ void | |||
| 2264 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, | 2297 | copy_intervals_to_string (Lisp_Object string, struct buffer *buffer, |
| 2265 | ptrdiff_t position, ptrdiff_t length) | 2298 | ptrdiff_t position, ptrdiff_t length) |
| 2266 | { | 2299 | { |
| 2267 | INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer), | 2300 | INTERVAL interval_copy = copy_intervals (buffer_intervals (buffer), |
| 2268 | position, length); | 2301 | position, length); |
| 2269 | if (!interval_copy) | 2302 | if (!interval_copy) |
| 2270 | return; | 2303 | return; |
| 2271 | 2304 | ||
| 2272 | interval_set_object (interval_copy, string); | 2305 | set_interval_object (interval_copy, string); |
| 2273 | string_set_intervals (string, interval_copy); | 2306 | set_string_intervals (string, interval_copy); |
| 2274 | } | 2307 | } |
| 2275 | 2308 | ||
| 2276 | /* Return 1 if strings S1 and S2 have identical properties; 0 otherwise. | 2309 | /* Return 1 if strings S1 and S2 have identical properties; 0 otherwise. |
| @@ -2283,8 +2316,8 @@ compare_string_intervals (Lisp_Object s1, Lisp_Object s2) | |||
| 2283 | ptrdiff_t pos = 0; | 2316 | ptrdiff_t pos = 0; |
| 2284 | ptrdiff_t end = SCHARS (s1); | 2317 | ptrdiff_t end = SCHARS (s1); |
| 2285 | 2318 | ||
| 2286 | i1 = find_interval (string_get_intervals (s1), 0); | 2319 | i1 = find_interval (string_intervals (s1), 0); |
| 2287 | i2 = find_interval (string_get_intervals (s2), 0); | 2320 | i2 = find_interval (string_intervals (s2), 0); |
| 2288 | 2321 | ||
| 2289 | while (pos < end) | 2322 | while (pos < end) |
| 2290 | { | 2323 | { |
| @@ -2409,13 +2442,13 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2409 | { | 2442 | { |
| 2410 | if ((i)->left) | 2443 | if ((i)->left) |
| 2411 | { | 2444 | { |
| 2412 | interval_set_plist (i, i->left->plist); | 2445 | set_interval_plist (i, i->left->plist); |
| 2413 | (i)->left->total_length = 0; | 2446 | (i)->left->total_length = 0; |
| 2414 | delete_interval ((i)->left); | 2447 | delete_interval ((i)->left); |
| 2415 | } | 2448 | } |
| 2416 | else | 2449 | else |
| 2417 | { | 2450 | { |
| 2418 | interval_set_plist (i, i->right->plist); | 2451 | set_interval_plist (i, i->right->plist); |
| 2419 | (i)->right->total_length = 0; | 2452 | (i)->right->total_length = 0; |
| 2420 | delete_interval ((i)->right); | 2453 | delete_interval ((i)->right); |
| 2421 | } | 2454 | } |
| @@ -2429,7 +2462,7 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2429 | void | 2462 | void |
| 2430 | set_intervals_multibyte (int multi_flag) | 2463 | set_intervals_multibyte (int multi_flag) |
| 2431 | { | 2464 | { |
| 2432 | INTERVAL i = buffer_get_intervals (current_buffer); | 2465 | INTERVAL i = buffer_intervals (current_buffer); |
| 2433 | 2466 | ||
| 2434 | if (i) | 2467 | if (i) |
| 2435 | set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE); | 2468 | set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE); |