diff options
author | rcombs <rcombs@rcombs.me> | 2020-08-30 13:09:20 -0500 |
---|---|---|
committer | rcombs <rcombs@rcombs.me> | 2020-08-30 22:45:37 -0500 |
commit | b3f9022b04ddf8872b99c28dd358d89e94dea12d (patch) | |
tree | b302ac0d627e46d833ccc6bf1734151c48fbd04a /libass | |
parent | 12cf524b831289cf67ba3432264fa01a69c3bbb5 (diff) | |
download | libass-b3f9022b04ddf8872b99c28dd358d89e94dea12d.tar.bz2 libass-b3f9022b04ddf8872b99c28dd358d89e94dea12d.tar.xz |
ass_parse: improve performance of tag name comparisons
Yes, this actually makes a major difference on some tag-heavy scripts.
This lets the whole function get inlined, rather than making a call out
to the libc's strcmp implementation. The libc's version is likely
much faster on longer strings, but we're only ever comparing against
strings that are a few characters long, so that doesn't really matter.
It also avoids making an extra pass for the strlen.
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass_parse.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libass/ass_parse.c b/libass/ass_parse.c index 2c367b0..b707944 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -73,12 +73,14 @@ static inline void push_arg(struct arg *args, int *nargs, char *start, char *end */ static inline int mystrcmp(char **p, const char *sample) { - int len = strlen(sample); - if (strncmp(*p, sample, len) == 0) { - (*p) += len; + char *p2; + for (p2 = *p; *sample != 0 && *p2 == *sample; p2++, sample++) + ; + if (*sample == 0) { + *p = p2; return 1; - } else - return 0; + } + return 0; } double ensure_font_size(ASS_Renderer *priv, double size) |