Mercurial > emacs
comparison src/textprop.c @ 1283:6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
author | Joseph Arceneaux <jla@gnu.org> |
---|---|
date | Thu, 01 Oct 1992 00:56:11 +0000 |
parents | bfd04f61eb16 |
children | 538cc0cd6d83 |
comparison
equal
deleted
inserted
replaced
1282:d6f0073d7e31 | 1283:6f4cbcc62eba |
---|---|
444 return previous->position + LENGTH (previous) - 1; | 444 return previous->position + LENGTH (previous) - 1; |
445 } | 445 } |
446 | 446 |
447 DEFUN ("add-text-properties", Fadd_text_properties, | 447 DEFUN ("add-text-properties", Fadd_text_properties, |
448 Sadd_text_properties, 4, 4, 0, | 448 Sadd_text_properties, 4, 4, 0, |
449 "Add the PROPERTIES (a property list) to the text of OBJECT\n\ | 449 "Add the PROPERTIES, a property list, to the text of OBJECT,\n\ |
450 (a string or buffer) in the range START to END. Returns t if any change\n\ | 450 a string or buffer, in the range START to END. Returns t if any change\n\ |
451 was made, nil otherwise.") | 451 was made, nil otherwise.") |
452 (object, start, end, properties) | 452 (object, start, end, properties) |
453 Lisp_Object object, start, end, properties; | 453 Lisp_Object object, start, end, properties; |
454 { | 454 { |
455 register INTERVAL i, unchanged; | 455 register INTERVAL i, unchanged; |
527 } | 527 } |
528 } | 528 } |
529 | 529 |
530 DEFUN ("set-text-properties", Fset_text_properties, | 530 DEFUN ("set-text-properties", Fset_text_properties, |
531 Sset_text_properties, 4, 4, 0, | 531 Sset_text_properties, 4, 4, 0, |
532 "Make the text of OBJECT (a string or buffer) have precisely\n\ | 532 "Make the text of OBJECT, a string or buffer, have precisely\n\ |
533 PROPERTIES (a list of properties) in the range START to END.\n\ | 533 PROPERTIES, a list of properties, in the range START to END.\n\ |
534 \n\ | 534 \n\ |
535 If called with a valid property list, return t (text was changed).\n\ | 535 If called with a valid property list, return t (text was changed).\n\ |
536 Otherwise return nil.") | 536 Otherwise return nil.") |
537 (object, start, end, properties) | 537 (object, start, end, properties) |
538 Lisp_Object object, start, end, properties; | 538 Lisp_Object object, start, end, properties; |
571 prev_changed = i; | 571 prev_changed = i; |
572 len -= LENGTH (i); | 572 len -= LENGTH (i); |
573 i = next_interval (i); | 573 i = next_interval (i); |
574 } | 574 } |
575 | 575 |
576 /* We are starting at the beginning of an interval, I */ | |
576 while (len > 0) | 577 while (len > 0) |
577 { | 578 { |
578 if (LENGTH (i) >= len) | 579 if (LENGTH (i) >= len) |
579 { | 580 { |
580 if (LENGTH (i) == len) | 581 if (LENGTH (i) > len) |
581 { | 582 i = split_interval_left (i, len + 1); |
582 if (NULL_INTERVAL_P (prev_changed)) | 583 |
583 set_properties (properties, i); | |
584 else | |
585 merge_interval_left (i); | |
586 return Qt; | |
587 } | |
588 | |
589 i = split_interval_left (i, len + 1); | |
590 if (NULL_INTERVAL_P (prev_changed)) | 584 if (NULL_INTERVAL_P (prev_changed)) |
591 set_properties (properties, i); | 585 set_properties (properties, i); |
592 else | 586 else |
593 merge_interval_left (i); | 587 merge_interval_left (i); |
594 return Qt; | 588 return Qt; |
609 return Qt; | 603 return Qt; |
610 } | 604 } |
611 | 605 |
612 DEFUN ("remove-text-properties", Fremove_text_properties, | 606 DEFUN ("remove-text-properties", Fremove_text_properties, |
613 Sremove_text_properties, 4, 4, 0, | 607 Sremove_text_properties, 4, 4, 0, |
614 "Remove the PROPERTIES (a property list) from the text of OBJECT\n\ | 608 "Remove the PROPERTIES, a property list, from the text of OBJECT,\n\ |
615 (a string or buffer) in the range START to END. Returns t if any change\n\ | 609 a string or buffer, in the range START to END. Returns t if any change\n\ |
616 was made, nil otherwise.") | 610 was made, nil otherwise.") |
617 (object, start, end, properties) | 611 (object, start, end, properties) |
618 Lisp_Object object, start, end, properties; | 612 Lisp_Object object, start, end, properties; |
619 { | 613 { |
620 register INTERVAL i, unchanged; | 614 register INTERVAL i, unchanged; |
692 "Remove all text properties from OBJECT (a string or buffer), in the\n\ | 686 "Remove all text properties from OBJECT (a string or buffer), in the\n\ |
693 range START to END. Returns t if any change was made, nil otherwise.") | 687 range START to END. Returns t if any change was made, nil otherwise.") |
694 (object, start, end) | 688 (object, start, end) |
695 Lisp_Object object, start, end; | 689 Lisp_Object object, start, end; |
696 { | 690 { |
697 register INTERVAL i, unchanged; | 691 register INTERVAL i; |
698 register prev_changed = NULL_INTERVAL; | 692 register prev_changed = NULL_INTERVAL; |
699 register int s, len, modified; | 693 register int s, len, modified; |
700 | 694 |
701 i = validate_interval_range (object, &start, &end, soft); | 695 i = validate_interval_range (object, &start, &end, soft); |
702 if (NULL_INTERVAL_P (i)) | 696 if (NULL_INTERVAL_P (i)) |
706 len = XINT (end) - s; | 700 len = XINT (end) - s; |
707 | 701 |
708 if (i->position != s) | 702 if (i->position != s) |
709 { | 703 { |
710 register int got; | 704 register int got; |
711 unchanged = i; | 705 register INTERVAL unchanged = i; |
712 | 706 |
713 /* If there are properties here, then this text will be modified. */ | 707 /* If there are properties here, then this text will be modified. */ |
714 if (!NILP (i->plist)) | 708 if (! NILP (i->plist)) |
715 { | 709 { |
716 i = split_interval_right (unchanged, s - unchanged->position + 1); | 710 i = split_interval_right (unchanged, s - unchanged->position + 1); |
717 i->plist = Qnil; | 711 i->plist = Qnil; |
718 modified++; | 712 modified++; |
719 | 713 |
727 if (LENGTH (i) == len) | 721 if (LENGTH (i) == len) |
728 return Qt; | 722 return Qt; |
729 | 723 |
730 got = LENGTH (i); | 724 got = LENGTH (i); |
731 } | 725 } |
732 /* If the text of i is without any properties, and contains | 726 /* If the text of I is without any properties, and contains |
733 LEN or more characters, then we return witout changing anything.*/ | 727 LEN or more characters, then we may return without changing |
728 anything.*/ | |
734 else if (LENGTH (i) - (s - i->position) <= len) | 729 else if (LENGTH (i) - (s - i->position) <= len) |
735 return Qnil; | 730 return Qnil; |
731 /* The amount of text to change extends past I, so just note | |
732 how much we've gotten. */ | |
736 else | 733 else |
737 got = LENGTH (i) - (s - i->position); | 734 got = LENGTH (i) - (s - i->position); |
738 | 735 |
739 len -= got; | 736 len -= got; |
740 prev_changed = i; | 737 prev_changed = i; |
744 /* We are starting at the beginning of an interval, I. */ | 741 /* We are starting at the beginning of an interval, I. */ |
745 while (len > 0) | 742 while (len > 0) |
746 { | 743 { |
747 if (LENGTH (i) >= len) | 744 if (LENGTH (i) >= len) |
748 { | 745 { |
749 /* If this last interval is exactly the right length, | 746 /* If I has no properties, simply merge it if possible. */ |
750 or is already without properties, then there's nothing | 747 if (NILP (i->plist)) |
751 to do except merge it if possible. */ | |
752 if (NILP (i->plist) || LENGTH (i) == len) | |
753 { | 748 { |
754 if (! NULL_INTERVAL_P (prev_changed)) | 749 if (! NULL_INTERVAL_P (prev_changed)) |
755 merge_interval_left (i); | 750 merge_interval_left (i); |
756 | 751 |
757 return modified ? Qt : Qnil; | 752 return modified ? Qt : Qnil; |
758 } | 753 } |
759 | 754 |
760 /* Here we know the last interval is longer than LEN and | 755 if (LENGTH (i) > len) |
761 has properties. */ | 756 i = split_interval_left (i, len + 1); |
762 i = split_interval_left (i, len + 1); | |
763 modified += erase_properties (i); | |
764 if (! NULL_INTERVAL_P (prev_changed)) | 757 if (! NULL_INTERVAL_P (prev_changed)) |
765 merge_interval_left (i); | 758 merge_interval_left (i); |
766 | 759 else |
767 return modified ? Qt : Qnil; | 760 i->plist = Qnil; |
768 } | 761 |
769 | 762 return Qt; |
763 } | |
764 | |
765 /* Here if we still need to erase past the end of I */ | |
770 len -= LENGTH (i); | 766 len -= LENGTH (i); |
771 if (NULL_INTERVAL_P (prev_changed)) | 767 if (NULL_INTERVAL_P (prev_changed)) |
772 { | 768 { |
773 modified += erase_properties (i); | 769 modified += erase_properties (i); |
774 prev_changed = i; | 770 prev_changed = i; |
775 } | 771 } |
776 else | 772 else |
777 { | 773 { |
778 if (! NULL_INTERVAL_P (i)) | 774 modified += ! NILP (i->plist); |
779 modified++; | 775 /* Merging I will give it the properties of PREV_CHANGED. */ |
780 prev_changed = i = merge_interval_left (i); | 776 prev_changed = i = merge_interval_left (i); |
781 } | 777 } |
782 | 778 |
783 i = next_interval (i); | 779 i = next_interval (i); |
784 } | 780 } |