summaryrefslogtreecommitdiff
path: root/source/html/css-apply.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-01-06 11:55:33 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-01-06 12:13:32 +0100
commita135e87d96bcf33c27f633f0ecfc5d158a4e0571 (patch)
tree92d9a3c57baba88ba2a4b8604973cb3426c068b5 /source/html/css-apply.c
parent041a2c827efbf2ed0931426129e38aef9412177f (diff)
downloadmupdf-a135e87d96bcf33c27f633f0ecfc5d158a4e0571.tar.xz
epub: Optimize CSS selector matching.
Remove strcpy and strtok calls when matching class conditions.
Diffstat (limited to 'source/html/css-apply.c')
-rw-r--r--source/html/css-apply.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/source/html/css-apply.c b/source/html/css-apply.c
index 40359d28..345a307f 100644
--- a/source/html/css-apply.c
+++ b/source/html/css-apply.c
@@ -217,15 +217,18 @@ static int
match_class_condition(fz_xml *node, const char *p)
{
const char *s = fz_xml_att(node, "class");
- char buf[1024];
+ const char *ss;
+ int n;
if (s) {
- strcpy(buf, s);
- s = strtok(buf, " ");
- while (s) {
- if (!strcmp(s, p))
- return 1;
- s = strtok(NULL, " ");
- }
+ /* Try matching whole property first. */
+ if (!strcmp(s, p))
+ return 1;
+
+ /* Look for matching words. */
+ n = strlen(p);
+ ss = strstr(s, p);
+ if (ss && (ss[n] == ' ' || ss[n] == 0) && (ss == s || ss[-1] == ' '))
+ return 1;
}
return 0;
}