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.
This commit is contained in:
Oleg Oshmyan 2017-10-29 00:19:37 +03:00 committed by wm4
parent e9dc4ac86f
commit 98986948e8
1 changed files with 3 additions and 2 deletions

View File

@ -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);
}
}