summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2017-10-29 00:19:37 +0300
committerwm4 <wm4@nowhere>2017-10-30 12:44:11 +0100
commit98986948e8e124c5fe5beb4afa12c6995940fbb6 (patch)
tree9f3422f2ba8164283f94ca82a3fe767c68207535 /sub
parente9dc4ac86f9dbd59147963d08ec8447bba3ed0bb (diff)
downloadmpv-98986948e8e124c5fe5beb4afa12c6995940fbb6.tar.bz2
mpv-98986948e8e124c5fe5beb4afa12c6995940fbb6.tar.xz
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.
Diffstat (limited to 'sub')
-rw-r--r--sub/lavc_conv.c5
1 files 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);
}
}