aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2004-10-25 02:03:47 +0000
committerKenichi Handa2004-10-25 02:03:47 +0000
commitfc1062f54140bedbaf27f8938325543d3ecc8aa8 (patch)
treefdda8986afa2d7693cc614a008859831b38af7c8
parent832fe7204e7ec0c7b98d977f1e0fa92a79cbc60f (diff)
downloademacs-fc1062f54140bedbaf27f8938325543d3ecc8aa8.tar.gz
emacs-fc1062f54140bedbaf27f8938325543d3ecc8aa8.zip
(fontset_pattern_regexp): Optimize for the case that
PATTERN is full XLFD.
-rw-r--r--src/ChangeLog5
-rw-r--r--src/fontset.c26
2 files changed, 27 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8544a1781af..1490b34b4a9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12004-10-25 Kenichi Handa <handa@m17n.org>
2
3 * fontset.c (fontset_pattern_regexp): Optimize for the case that
4 PATTERN is full XLFD.
5
12004-10-24 Kenichi Handa <handa@m17n.org> 62004-10-24 Kenichi Handa <handa@m17n.org>
2 7
3 * regex.h (enum reg_errcode_t): New value REG_ERANGEX. 8 * regex.h (enum reg_errcode_t): New value REG_ERANGEX.
diff --git a/src/fontset.c b/src/fontset.c
index 960b6fcb34b..bccbce8bf45 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -789,16 +789,34 @@ fontset_pattern_regexp (pattern)
789 || strcmp (SDATA (pattern), CACHED_FONTSET_NAME)) 789 || strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
790 { 790 {
791 /* We must at first update the cached data. */ 791 /* We must at first update the cached data. */
792 char *regex = (char *) alloca (SCHARS (pattern) * 2 + 3); 792 char *regex, *p0, *p1;
793 char *p0, *p1 = regex; 793 int ndashes = 0, nstars = 0;
794
795 for (p0 = SDATA (pattern); *p0; p0++)
796 {
797 if (*p0 == '-')
798 ndashes++;
799 else if (*p0 == '*')
800 nstars++;
801 }
802
803 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
804 we convert "*" to "[^-]*" which is much faster in regular
805 expression matching. */
806 if (ndashes < 14)
807 p1 = regex = (char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
808 else
809 p1 = regex = (char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
794 810
795 /* Convert "*" to ".*", "?" to ".". */
796 *p1++ = '^'; 811 *p1++ = '^';
797 for (p0 = (char *) SDATA (pattern); *p0; p0++) 812 for (p0 = (char *) SDATA (pattern); *p0; p0++)
798 { 813 {
799 if (*p0 == '*') 814 if (*p0 == '*')
800 { 815 {
801 *p1++ = '.'; 816 if (ndashes < 14)
817 *p1++ = '.';
818 else
819 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
802 *p1++ = '*'; 820 *p1++ = '*';
803 } 821 }
804 else if (*p0 == '?') 822 else if (*p0 == '?')