summaryrefslogtreecommitdiff
blob: e2040fcd4b108e168f1fb8cd9234e04ca8e6f17c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
From f6244d2cf231e1dc756f3e941e61b9bf124879bb Mon Sep 17 00:00:00 2001
From: Akira TAGOH <akira@tagoh.org>
Date: Wed, 08 May 2013 02:57:49 +0000
Subject: Use the glob matching for filename

Regex is expensive to compare filenames. we already have the glob matching
and it works enough in this case.

Prior to this change, renaming FcConfigGlobMatch() to FcStrGlobMatch() and moving to fcstr.c
---
diff --git a/src/fccfg.c b/src/fccfg.c
index 7da50b5..fcdf73e 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -2211,57 +2211,13 @@ FcConfigGlobAdd (FcConfig	*config,
 }
 
 static FcBool
-FcConfigGlobMatch (const FcChar8    *glob,
-		   const FcChar8    *string)
-{
-    FcChar8	c;
-
-    while ((c = *glob++))
-    {
-	switch (c) {
-	case '*':
-	    /* short circuit common case */
-	    if (!*glob)
-		return FcTrue;
-	    /* short circuit another common case */
-	    if (strchr ((char *) glob, '*') == 0)
-	    {
-		size_t l1, l2;
-
-		l1 = strlen ((char *) string);
-		l2 = strlen ((char *) glob);
-		if (l1 < l2)
-		    return FcFalse;
-		string += (l1 - l2);
-	    }
-	    while (*string)
-	    {
-		if (FcConfigGlobMatch (glob, string))
-		    return FcTrue;
-		string++;
-	    }
-	    return FcFalse;
-	case '?':
-	    if (*string++ == '\0')
-		return FcFalse;
-	    break;
-	default:
-	    if (*string++ != c)
-		return FcFalse;
-	    break;
-	}
-    }
-    return *string == '\0';
-}
-
-static FcBool
 FcConfigGlobsMatch (const FcStrSet	*globs,
 		    const FcChar8	*string)
 {
     int	i;
 
     for (i = 0; i < globs->num; i++)
-	if (FcConfigGlobMatch (globs->strs[i], string))
+	if (FcStrGlobMatch (globs->strs[i], string))
 	    return FcTrue;
     return FcFalse;
 }
diff --git a/src/fcint.h b/src/fcint.h
index 8919958..65bf333 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -1090,6 +1090,10 @@ FcPrivate int
 FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcChar8 *delims);
 
 FcPrivate FcBool
+FcStrGlobMatch (const FcChar8 *glob,
+		const FcChar8 *string);
+
+FcPrivate FcBool
 FcStrUsesHome (const FcChar8 *s);
 
 FcPrivate FcChar8 *
diff --git a/src/fcmatch.c b/src/fcmatch.c
index 2d7b798..84c9a9a 100644
--- a/src/fcmatch.c
+++ b/src/fcmatch.c
@@ -196,12 +196,10 @@ FcCompareFilename (FcValue *v1, FcValue *v2)
 	    return 0.0;
 	else if (FcStrCmpIgnoreCase (s1, s2) == 0)
 	    return 1.0;
-	else if (FcStrRegexCmp (s2, s1))
+	else if (FcStrGlobMatch (s1, s2))
 	    return 2.0;
-	else if (FcStrRegexCmpIgnoreCase (s2, s1))
-	    return 3.0;
 	else
-	    return 4.0;
+	    return 3.0;
 }
 
 #define PRI_NULL(n)				\
diff --git a/src/fcstr.c b/src/fcstr.c
index 339a346..3a32031 100644
--- a/src/fcstr.c
+++ b/src/fcstr.c
@@ -459,6 +459,50 @@ FcStrMatchIgnoreCaseAndDelims (const FcChar8 *s1, const FcChar8 *s2, const FcCha
     return w1.src - s1 - 1;
 }
 
+FcBool
+FcStrGlobMatch (const FcChar8 *glob,
+		const FcChar8 *string)
+{
+    FcChar8	c;
+
+    while ((c = *glob++))
+    {
+	switch (c) {
+	case '*':
+	    /* short circuit common case */
+	    if (!*glob)
+		return FcTrue;
+	    /* short circuit another common case */
+	    if (strchr ((char *) glob, '*') == 0)
+	    {
+		size_t l1, l2;
+
+		l1 = strlen ((char *) string);
+		l2 = strlen ((char *) glob);
+		if (l1 < l2)
+		    return FcFalse;
+		string += (l1 - l2);
+	    }
+	    while (*string)
+	    {
+		if (FcStrGlobMatch (glob, string))
+		    return FcTrue;
+		string++;
+	    }
+	    return FcFalse;
+	case '?':
+	    if (*string++ == '\0')
+		return FcFalse;
+	    break;
+	default:
+	    if (*string++ != c)
+		return FcFalse;
+	    break;
+	}
+    }
+    return *string == '\0';
+}
+
 const FcChar8 *
 FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2)
 {
--
cgit v0.9.0.2-2-gbebe