From b3f9022b04ddf8872b99c28dd358d89e94dea12d Mon Sep 17 00:00:00 2001 From: rcombs Date: Sun, 30 Aug 2020 13:09:20 -0500 Subject: 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. --- libass/ass_parse.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libass') 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) -- cgit v1.2.3