simplification

This commit is contained in:
David Poetzsch-Heffter 2024-01-18 15:53:18 +01:00
parent 001125a9bf
commit 6483564893

View File

@ -56,16 +56,12 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
replacedSpans.push(repText); replacedSpans.push(repText);
} }
// Repeated replace is really slow for a large number of spans and long texts // It is important to only do one replace for all the spans combined.
// (for example for 4000 spans and 1.8MB of text it can take >10sec). // Otherwise this gets really slow on large texts with many spans because
// By only going through the text once, we can reduce the time to just a few milliseconds. // of all the string copies.
var s = text.split('¨C'); text = text.replace(/¨C(\d+)C/g, function (_wm, num) {
for (var ii = 1; ii < s.length; ++ii) { return replacedSpans[num];
var endIdx = s[ii].indexOf('C'); });
var span = replacedSpans[s[ii].substring(0, endIdx)];
s[ii] = span + s[ii].substring(endIdx + 1);
}
text = s.join('');
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText(); text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
return text; return text;