From 98986948e8e124c5fe5beb4afa12c6995940fbb6 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sun, 29 Oct 2017 00:19:37 +0300 Subject: lavc_conv: make disable_styles faster The current invocation of bstr_cut is as good as no cutting at all. Almost the entire header is reread in every iteration of the loop. I don't know how many styles libavcodec tends to generate, but if (now or in the future) it generates many, then this loop is slow for no good reason. If anything, the code would be more clear and have the same performance if it didn't call bstr_cut at all. The intention here (and the sensible thing regardless) seems to be to skip the part of the string that bstr_find has already looked through and found nothing. This commit additionally skips the whole substring, because overlapping matches are impossible. --- sub/lavc_conv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sub/lavc_conv.c b/sub/lavc_conv.c index 843da42ca7..06b975660f 100644 --- a/sub/lavc_conv.c +++ b/sub/lavc_conv.c @@ -57,12 +57,13 @@ static const char *get_lavc_format(const char *format) // We always want the user defined style instead. static void disable_styles(bstr header) { + bstr style = bstr0("\nStyle: "); while (header.len) { - int n = bstr_find(header, bstr0("\nStyle: ")); + int n = bstr_find(header, style); if (n < 0) break; header.start[n + 1] = '#'; // turn into a comment - header = bstr_cut(header, 2); + header = bstr_cut(header, n + style.len); } } -- cgit v1.2.3