Mercurial > hg > xemacs-beta
comparison src/text.c @ 801:2b676dc88c66
[xemacs-hg @ 2002-04-01 03:58:02 by ben]
bug fixes (e.g. ballooning on X windows)
Makefile.in.in: Try to make the Makefile notice if its source Makefile.in.in is
changed, and regenerate and run itself.
Use a bigger default SHEAP_ADJUSTMENT on Cygwin; otherwise you
can't compile under Mule if a Lisp file has changed. (can't run
temacs)
TODO.ben-mule-21-5: update.
mule/mule-cmds.el: Hash the result of mswindows-get-language-environment-from-locale,
since it's very expensive (and causes huge ballooning of memory
under X Windows, since it's called from x-get-resource).
cl-extra.el, code-files.el, files.el, simple.el, subr.el, x-faces.el: Create new string-equal-ignore-case, based on built-in
compare-strings -- compare strings ignoring case without the need
to generate garbage by calling downcase. Use it in equalp and
elsewhere.
alloc.c, bytecode.c, chartab.c, data.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-unixoid.c, extents.c, file-coding.c, fileio.c, fns.c, glyphs.c, gutter.c, lisp-union.h, lisp.h, mule-charset.c, nt.c, process-unix.c, process.c, specifier.c, symbols.c, sysdep.c, sysdep.h, text.c, toolbar.c: Try to implement GC triggering based on percentage of total memory
usage. Not currently activated (percentage set to 0) because not
quite working. Add `memory-usage' primitive to return XEmacs'
idea of its memory usage.
Add primitive compare-strings, compatible with FSF 21.1 -- can
compare any part of two strings, optionally ignoring case.
Improve qxe() functions in text.c for text comparison.
Use RETURN_NOT_REACHED to try to avoid warnings about unreachable
code.
Add volatile_make_int() to fix warning in unix_send_process().
author | ben |
---|---|
date | Mon, 01 Apr 2002 03:59:04 +0000 |
parents | a5954632b187 |
children | a634e3b7acc8 |
comparison
equal
deleted
inserted
replaced
800:a5954632b187 | 801:2b676dc88c66 |
---|---|
737 qxestrncasecmp_c (const Intbyte *s1, const Char_ASCII *s2, Bytecount len) | 737 qxestrncasecmp_c (const Intbyte *s1, const Char_ASCII *s2, Bytecount len) |
738 { | 738 { |
739 return qxestrncasecmp (s1, (const Intbyte *) s2, len); | 739 return qxestrncasecmp (s1, (const Intbyte *) s2, len); |
740 } | 740 } |
741 | 741 |
742 /* Compare LEN_FROM_S1 worth of characters from S1 with the same number of | |
743 characters from S2, case insensitive. NOTE: Downcasing can convert | |
744 characters from one length in bytes to another, so reversing S1 and S2 | |
745 is *NOT* a symmetric operations! You must choose a length that agrees | |
746 with S1. */ | |
747 | |
742 int | 748 int |
743 qxestrncasecmp_i18n (const Intbyte *s1, const Intbyte *s2, Bytecount len) | 749 qxestrncasecmp_i18n (const Intbyte *s1, const Intbyte *s2, |
744 { | 750 Bytecount len_from_s1) |
745 while (len > 0) | 751 { |
752 while (len_from_s1 > 0) | |
746 { | 753 { |
747 const Intbyte *old_s1 = s1; | 754 const Intbyte *old_s1 = s1; |
748 int diff = (DOWNCASE (0, charptr_emchar (s1)) - | 755 int diff = (DOWNCASE (0, charptr_emchar (s1)) - |
749 DOWNCASE (0, charptr_emchar (s2))); | 756 DOWNCASE (0, charptr_emchar (s2))); |
750 if (diff != 0) | 757 if (diff != 0) |
751 return diff; | 758 return diff; |
752 if (!*s1) | 759 if (!*s1) |
753 return 0; | 760 return 0; |
754 INC_CHARPTR (s1); | 761 INC_CHARPTR (s1); |
755 INC_CHARPTR (s2); | 762 INC_CHARPTR (s2); |
756 len -= s1 - old_s1; | 763 len_from_s1 -= s1 - old_s1; |
757 } | 764 } |
758 | 765 |
759 return 0; | 766 return 0; |
760 } | 767 } |
761 | 768 |
762 int | 769 int |
763 qxememcmp (const Intbyte *s1, const Intbyte *s2, Bytecount len) | 770 qxememcmp (const Intbyte *s1, const Intbyte *s2, Bytecount len) |
764 { | 771 { |
765 return memcmp (s1, s2, len); | 772 return memcmp (s1, s2, len); |
773 } | |
774 | |
775 int | |
776 qxememcmp4 (const Intbyte *s1, Bytecount len1, | |
777 const Intbyte *s2, Bytecount len2) | |
778 { | |
779 int retval = qxememcmp (s1, s2, min (len1, len2)); | |
780 if (retval) | |
781 return retval; | |
782 return len1 - len2; | |
766 } | 783 } |
767 | 784 |
768 int | 785 int |
769 qxememcasecmp (const Intbyte *s1, const Intbyte *s2, Bytecount len) | 786 qxememcasecmp (const Intbyte *s1, const Intbyte *s2, Bytecount len) |
770 { | 787 { |
780 | 797 |
781 return 0; | 798 return 0; |
782 } | 799 } |
783 | 800 |
784 int | 801 int |
785 qxememcasecmp_i18n (const Intbyte *s1, const Intbyte *s2, Bytecount len) | 802 qxememcasecmp4 (const Intbyte *s1, Bytecount len1, |
786 { | 803 const Intbyte *s2, Bytecount len2) |
787 while (len > 0) | 804 { |
805 int retval = qxememcasecmp (s1, s2, min (len1, len2)); | |
806 if (retval) | |
807 return retval; | |
808 return len1 - len2; | |
809 } | |
810 | |
811 /* Do a character-by-character comparison, returning "which is greater" by | |
812 comparing the Emchar values. (#### Should have option to compare Unicode | |
813 points) */ | |
814 | |
815 int | |
816 qxetextcmp (const Intbyte *s1, Bytecount len1, | |
817 const Intbyte *s2, Bytecount len2) | |
818 { | |
819 while (len1 > 0 && len2 > 0) | |
788 { | 820 { |
789 const Intbyte *old_s1 = s1; | 821 const Intbyte *old_s1 = s1; |
822 const Intbyte *old_s2 = s2; | |
823 int diff = charptr_emchar (s1) - charptr_emchar (s2); | |
824 if (diff != 0) | |
825 return diff; | |
826 INC_CHARPTR (s1); | |
827 INC_CHARPTR (s2); | |
828 len1 -= s1 - old_s1; | |
829 len2 -= s2 - old_s2; | |
830 } | |
831 | |
832 assert (len1 >= 0 && len2 >= 0); | |
833 return len1 - len2; | |
834 } | |
835 | |
836 int | |
837 qxetextcmp_matching (const Intbyte *s1, Bytecount len1, | |
838 const Intbyte *s2, Bytecount len2, | |
839 Charcount *matching) | |
840 { | |
841 *matching = 0; | |
842 while (len1 > 0 && len2 > 0) | |
843 { | |
844 const Intbyte *old_s1 = s1; | |
845 const Intbyte *old_s2 = s2; | |
846 int diff = charptr_emchar (s1) - charptr_emchar (s2); | |
847 if (diff != 0) | |
848 return diff; | |
849 INC_CHARPTR (s1); | |
850 INC_CHARPTR (s2); | |
851 len1 -= s1 - old_s1; | |
852 len2 -= s2 - old_s2; | |
853 (*matching)++; | |
854 } | |
855 | |
856 assert (len1 >= 0 && len2 >= 0); | |
857 return len1 - len2; | |
858 } | |
859 | |
860 /* Do a character-by-character comparison, returning "which is greater" by | |
861 comparing the Emchar values, case insensitively (by downcasing both | |
862 first). (#### Should have option to compare Unicode points) | |
863 | |
864 In this case, both lengths must be specified becaused downcasing can | |
865 convert characters from one length in bytes to another; therefore, two | |
866 blocks of text of different length might be equal. If both compare | |
867 equal up to the limit in length of one but not the other, the longer one | |
868 is "greater". */ | |
869 | |
870 int | |
871 qxetextcasecmp (const Intbyte *s1, Bytecount len1, | |
872 const Intbyte *s2, Bytecount len2) | |
873 { | |
874 while (len1 > 0 && len2 > 0) | |
875 { | |
876 const Intbyte *old_s1 = s1; | |
877 const Intbyte *old_s2 = s2; | |
790 int diff = (DOWNCASE (0, charptr_emchar (s1)) - | 878 int diff = (DOWNCASE (0, charptr_emchar (s1)) - |
791 DOWNCASE (0, charptr_emchar (s2))); | 879 DOWNCASE (0, charptr_emchar (s2))); |
792 if (diff != 0) | 880 if (diff != 0) |
793 return diff; | 881 return diff; |
794 INC_CHARPTR (s1); | 882 INC_CHARPTR (s1); |
795 INC_CHARPTR (s2); | 883 INC_CHARPTR (s2); |
796 len -= s1 - old_s1; | 884 len1 -= s1 - old_s1; |
797 } | 885 len2 -= s2 - old_s2; |
798 | 886 } |
799 return 0; | 887 |
888 assert (len1 >= 0 && len2 >= 0); | |
889 return len1 - len2; | |
890 } | |
891 | |
892 /* Like qxetextcasecmp() but also return number of characters at | |
893 beginning that match. */ | |
894 | |
895 int | |
896 qxetextcasecmp_matching (const Intbyte *s1, Bytecount len1, | |
897 const Intbyte *s2, Bytecount len2, | |
898 Charcount *matching) | |
899 { | |
900 *matching = 0; | |
901 while (len1 > 0 && len2 > 0) | |
902 { | |
903 const Intbyte *old_s1 = s1; | |
904 const Intbyte *old_s2 = s2; | |
905 int diff = (DOWNCASE (0, charptr_emchar (s1)) - | |
906 DOWNCASE (0, charptr_emchar (s2))); | |
907 if (diff != 0) | |
908 return diff; | |
909 INC_CHARPTR (s1); | |
910 INC_CHARPTR (s2); | |
911 len1 -= s1 - old_s1; | |
912 len2 -= s2 - old_s2; | |
913 (*matching)++; | |
914 } | |
915 | |
916 assert (len1 >= 0 && len2 >= 0); | |
917 return len1 - len2; | |
800 } | 918 } |
801 | 919 |
802 int | 920 int |
803 lisp_strcasecmp (Lisp_Object s1, Lisp_Object s2) | 921 lisp_strcasecmp (Lisp_Object s1, Lisp_Object s2) |
804 { | 922 { |
824 } | 942 } |
825 | 943 |
826 int | 944 int |
827 lisp_strcasecmp_i18n (Lisp_Object s1, Lisp_Object s2) | 945 lisp_strcasecmp_i18n (Lisp_Object s1, Lisp_Object s2) |
828 { | 946 { |
829 Intbyte *p1 = XSTRING_DATA (s1); | 947 return qxetextcasecmp (XSTRING_DATA (s1), XSTRING_LENGTH (s1), |
830 Intbyte *p2 = XSTRING_DATA (s2); | 948 XSTRING_DATA (s2), XSTRING_LENGTH (s2)); |
831 Intbyte *e1 = p1 + XSTRING_LENGTH (s1); | |
832 Intbyte *e2 = p2 + XSTRING_LENGTH (s2); | |
833 | |
834 /* again, we use a symmetric algorithm and favor clarity over | |
835 nanosecond improvements. */ | |
836 while (1) | |
837 { | |
838 /* if we reached the end of either string, compare lengths. | |
839 do NOT compare the final null byte against anything, in case | |
840 the other string also has a null byte at that position. */ | |
841 assert (p1 <= e1); | |
842 assert (p2 <= e2); | |
843 if (p1 == e1 || p2 == e2) | |
844 return e1 - e2; | |
845 if (DOWNCASE (0, charptr_emchar (p1)) != | |
846 DOWNCASE (0, charptr_emchar (p2))) | |
847 return (DOWNCASE (0, charptr_emchar (p1)) - | |
848 DOWNCASE (0, charptr_emchar (p2))); | |
849 INC_CHARPTR (p1); | |
850 INC_CHARPTR (p2); | |
851 } | |
852 } | 949 } |
853 | 950 |
854 | 951 |
855 /************************************************************************/ | 952 /************************************************************************/ |
856 /* conversion between textual representations */ | 953 /* conversion between textual representations */ |
1146 assert ((is_c != 0) == (data != 0)); | 1243 assert ((is_c != 0) == (data != 0)); |
1147 assert (fold_case >= 0 && fold_case <= 2); | 1244 assert (fold_case >= 0 && fold_case <= 2); |
1148 | 1245 |
1149 { | 1246 { |
1150 Bytecount dstlen; | 1247 Bytecount dstlen; |
1151 int result; | |
1152 const Intbyte *src = ei->data_, *dst; | 1248 const Intbyte *src = ei->data_, *dst; |
1153 Bytecount cmplen; | |
1154 | 1249 |
1155 if (data) | 1250 if (data) |
1156 { | 1251 { |
1157 dst = data; | 1252 dst = data; |
1158 dstlen = qxestrlen (data); | 1253 dstlen = qxestrlen (data); |
1164 } | 1259 } |
1165 | 1260 |
1166 if (is_c) | 1261 if (is_c) |
1167 EI_ASSERT_ASCII ((Char_ASCII *) dst, dstlen); | 1262 EI_ASSERT_ASCII ((Char_ASCII *) dst, dstlen); |
1168 | 1263 |
1169 cmplen = min (len, dstlen); | 1264 return (fold_case == 0 ? qxememcmp4 (src, len, dst, dstlen) : |
1170 result = (fold_case == 0 ? qxememcmp (src, dst, cmplen) : | 1265 fold_case == 1 ? qxememcasecmp4 (src, len, dst, dstlen) : |
1171 fold_case == 1 ? qxememcasecmp (src, dst, cmplen) : | 1266 qxetextcasecmp (src, len, dst, dstlen)); |
1172 qxememcasecmp_i18n (src, dst, cmplen)); | |
1173 | |
1174 if (result) | |
1175 return result; | |
1176 | |
1177 return len - dstlen; | |
1178 } | 1267 } |
1179 } | 1268 } |
1180 | 1269 |
1181 Intbyte * | 1270 Intbyte * |
1182 eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out, Internal_Format fmt) | 1271 eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out, Internal_Format fmt) |