mirror of https://github.com/mpv-player/mpv
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:
parent
e9dc4ac86f
commit
98986948e8
|
@ -57,12 +57,13 @@ static const char *get_lavc_format(const char *format)
|
||||||
// We always want the user defined style instead.
|
// We always want the user defined style instead.
|
||||||
static void disable_styles(bstr header)
|
static void disable_styles(bstr header)
|
||||||
{
|
{
|
||||||
|
bstr style = bstr0("\nStyle: ");
|
||||||
while (header.len) {
|
while (header.len) {
|
||||||
int n = bstr_find(header, bstr0("\nStyle: "));
|
int n = bstr_find(header, style);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
break;
|
break;
|
||||||
header.start[n + 1] = '#'; // turn into a comment
|
header.start[n + 1] = '#'; // turn into a comment
|
||||||
header = bstr_cut(header, 2);
|
header = bstr_cut(header, n + style.len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue