aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa <[email protected]>2004-10-25 02:03:47 +0000
committerKenichi Handa <[email protected]>2004-10-25 02:03:47 +0000
commitfc1062f54140bedbaf27f8938325543d3ecc8aa8 (patch)
treefdda8986afa2d7693cc614a008859831b38af7c8
parent832fe7204e7ec0c7b98d977f1e0fa92a79cbc60f (diff)
(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 8544a1781a..1490b34b4a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-25 Kenichi Handa <[email protected]>
+
+ * fontset.c (fontset_pattern_regexp): Optimize for the case that
+ PATTERN is full XLFD.
+
2004-10-24 Kenichi Handa <[email protected]>
* regex.h (enum reg_errcode_t): New value REG_ERANGEX.
diff --git a/src/fontset.c b/src/fontset.c
index 960b6fcb34..bccbce8bf4 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -789,16 +789,34 @@ fontset_pattern_regexp (pattern)
|| strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
{
/* We must at first update the cached data. */
- char *regex = (char *) alloca (SCHARS (pattern) * 2 + 3);
- char *p0, *p1 = regex;
+ char *regex, *p0, *p1;
+ int ndashes = 0, nstars = 0;
+
+ for (p0 = SDATA (pattern); *p0; p0++)
+ {
+ if (*p0 == '-')
+ ndashes++;
+ else if (*p0 == '*')
+ nstars++;
+ }
+
+ /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
+ we convert "*" to "[^-]*" which is much faster in regular
+ expression matching. */
+ if (ndashes < 14)
+ p1 = regex = (char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
+ else
+ p1 = regex = (char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
- /* Convert "*" to ".*", "?" to ".". */
*p1++ = '^';
for (p0 = (char *) SDATA (pattern); *p0; p0++)
{
if (*p0 == '*')
{
- *p1++ = '.';
+ if (ndashes < 14)
+ *p1++ = '.';
+ else
+ *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
*p1++ = '*';
}
else if (*p0 == '?')