aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Arceneaux1992-10-01 00:56:11 +0000
committerJoseph Arceneaux1992-10-01 00:56:11 +0000
commitcd7d971d0692c72edc761bde8b9abb5d8dc15bce (patch)
treef8d8231cc712b586193fbc368a78f631ab94b9ed
parent9e7cd9225e492f8e3b10c06a5425de9ddadbdb66 (diff)
downloademacs-cd7d971d0692c72edc761bde8b9abb5d8dc15bce.tar.gz
emacs-cd7d971d0692c72edc761bde8b9abb5d8dc15bce.zip
Minor optimizations of Fset_text_properties and Ferase_text_properties.
-rw-r--r--src/textprop.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/src/textprop.c b/src/textprop.c
index 1600928fde6..052b14081a5 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -446,8 +446,8 @@ a string or buffer. Returns nil if unsuccessful.")
446 446
447DEFUN ("add-text-properties", Fadd_text_properties, 447DEFUN ("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\ 450a string or buffer, in the range START to END. Returns t if any change\n\
451was made, nil otherwise.") 451was 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;
@@ -529,8 +529,8 @@ was made, nil otherwise.")
529 529
530DEFUN ("set-text-properties", Fset_text_properties, 530DEFUN ("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\
533PROPERTIES (a list of properties) in the range START to END.\n\ 533PROPERTIES, a list of properties, in the range START to END.\n\
534\n\ 534\n\
535If called with a valid property list, return t (text was changed).\n\ 535If called with a valid property list, return t (text was changed).\n\
536Otherwise return nil.") 536Otherwise return nil.")
@@ -573,20 +573,14 @@ Otherwise return nil.")
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 set_properties (properties, i);
584 else
585 merge_interval_left (i);
586 return Qt;
587 }
588 583
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
@@ -611,8 +605,8 @@ Otherwise return nil.")
611 605
612DEFUN ("remove-text-properties", Fremove_text_properties, 606DEFUN ("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\ 609a string or buffer, in the range START to END. Returns t if any change\n\
616was made, nil otherwise.") 610was 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;
@@ -694,7 +688,7 @@ 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
@@ -708,10 +702,10 @@ range START to END. Returns t if any change was made, nil otherwise.")
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;
@@ -729,10 +723,13 @@ range START to END. Returns t if any change was made, nil otherwise.")
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
@@ -746,10 +743,8 @@ range START to END. Returns t if any change was made, nil otherwise.")
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);
@@ -757,16 +752,17 @@ range START to END. Returns t if any change was made, nil otherwise.")
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);
759 else
760 i->plist = Qnil;
766 761
767 return modified ? Qt : Qnil; 762 return Qt;
768 } 763 }
769 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 {
@@ -775,8 +771,8 @@ range START to END. Returns t if any change was made, nil otherwise.")
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