]> git.eshelyaron.com Git - emacs.git/commitdiff
(fontset_pattern_regexp): Optimize for the case that
authorKenichi Handa <handa@m17n.org>
Mon, 25 Oct 2004 02:03:47 +0000 (02:03 +0000)
committerKenichi Handa <handa@m17n.org>
Mon, 25 Oct 2004 02:03:47 +0000 (02:03 +0000)
PATTERN is full XLFD.

src/ChangeLog
src/fontset.c

index 8544a1781af073306962ee0c02d3d88cadc2f55d..1490b34b4a9cce9681b2a29f3158711e204b1fee 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-25  Kenichi Handa  <handa@m17n.org>
+
+       * fontset.c (fontset_pattern_regexp): Optimize for the case that
+       PATTERN is full XLFD.
+
 2004-10-24  Kenichi Handa  <handa@m17n.org>
 
        * regex.h (enum reg_errcode_t): New value REG_ERANGEX.
index 960b6fcb34b2d3e5d4fc37cbeada0ebc98d2d30d..bccbce8bf45f96acecb15816753a18f2201ca2e8 100644 (file)
@@ -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 == '?')