Mercurial > emacs
comparison src/fontset.c @ 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 | 43067aee2f3e |
children | a17e7dae99c0 ae7fab96922c 0fe073a08cef |
comparison
equal
deleted
inserted
replaced
57684:0c6735b0abb2 | 57685:b935fc1cb542 |
---|---|
787 | 787 |
788 if (!CONSP (Vcached_fontset_data) | 788 if (!CONSP (Vcached_fontset_data) |
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 | 794 |
795 /* Convert "*" to ".*", "?" to ".". */ | 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); | |
810 | |
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 == '?') |
805 *p1++ = '.'; | 823 *p1++ = '.'; |
806 else | 824 else |