Speed up slow loading mp4 without subs as sub - thx Leon :)

Fix #5473
This commit is contained in:
niksedk 2021-11-14 13:51:15 +01:00
parent 0693d348c8
commit ed6c535349
2 changed files with 49 additions and 1 deletions

View File

@ -164,6 +164,54 @@ namespace Nikse.SubtitleEdit.Core.Common
return lines;
}
public static List<string> SplitToLines(this string s, int maxCount)
{
var lines = new List<string>();
int start = 0;
int max = Math.Min(maxCount, s.Length);
int i = 0;
while (i < max)
{
var ch = s[i];
if (ch == '\r')
{
if (i < s.Length - 2 && s[i + 1] == '\r' && s[i + 2] == '\n') // \r\r\n
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i += 3;
start = i;
continue;
}
if (i < s.Length - 1 && s[i + 1] == '\n') // \r\n
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i += 2;
start = i;
continue;
}
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i++;
start = i;
continue;
}
if (ch == '\n' || ch == '\u2028')
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i++;
start = i;
continue;
}
i++;
}
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
return lines;
}
public static int CountWords(this string source)
{
return HtmlUtil.RemoveHtmlTags(source, true).Split(new[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Length;

View File

@ -64,7 +64,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
var sub = new Subtitle();
var mdatLines = xmlAsString.SplitToLines();
var mdatLines = xmlAsString.SplitToLines(25_000);
format = sub.ReloadLoadSubtitle(mdatLines, null, format);
if (sub.Paragraphs.Count == 0)
{