changeset 57685:b935fc1cb542

(fontset_pattern_regexp): Optimize for the case that PATTERN is full XLFD.
author Kenichi Handa <handa@m17n.org>
date Mon, 25 Oct 2004 02:03:32 +0000
parents 0c6735b0abb2
children 1884184364e8
files src/fontset.c
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/fontset.c	Mon Oct 25 00:46:04 2004 +0000
+++ b/src/fontset.c	Mon Oct 25 02:03:32 2004 +0000
@@ -789,16 +789,34 @@
       || 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++;
+	}
 
-      /* Convert "*" to ".*", "?" to ".".  */
+      /* 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);
+
       *p1++ = '^';
       for (p0 = (char *) SDATA (pattern); *p0; p0++)
 	{
 	  if (*p0 == '*')
 	    {
-	      *p1++ = '.';
+	      if (ndashes < 14)
+		*p1++ = '.';
+	      else
+		*p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
 	      *p1++ = '*';
 	    }
 	  else if (*p0 == '?')