Fix remaining bottleneck in wikitext syntax highlighter

I was wondering why the performance when editing wikitext is
still so bad, and profiled it again. Turns out
StringStream.match() is still the bottleneck (even if already
100 times better than before Icbb1122).

The method is called with many different patterns from
mode/mediawiki/mediawiki.js. I profiled them individually and
found a single outlier. The idea is the same as in Icbb1122.
A pattern that is able to find something *in* a string is
doing nothing but wasting time, as StringStream.match() ignores
every result that is not at the start of the string.

The change adds the missing ^ anchor and wraps the regex pattern
from mw.config.get( 'wgUrlProtocols' ) (that is something like
"ftp:\/\/|http:\/\/|https:\/\/|…") in (?:…), which is a
non-matching group. This is necessary because of the | in the
pattern. The result is a pattern that looks like /^(?:…|…|…)/i.

I remember looking at this code while working on Icbb1122, but
didn't include it in the patch, and then forgot about it.

Bug: T270237
Bug: T270317
Change-Id: Iea2fd116b68704c3186b0edf965006cc7c6eda82
This commit is contained in:
Thiemo Kreuz 2021-02-05 16:07:40 +01:00
parent 81bd2fe546
commit cfecfbc099

View file

@ -23,7 +23,7 @@
CodeMirror.defineMode( 'mediawiki', function ( config /* , parserConfig */ ) {
var mwConfig = config.mwConfig,
urlProtocols = new RegExp( mwConfig.urlProtocols, 'i' ),
urlProtocols = new RegExp( '^(?:' + mwConfig.urlProtocols + ')', 'i' ),
permittedHtmlTags = { b: true, bdi: true, del: true, i: true, ins: true,
u: true, font: true, big: true, small: true, sub: true, sup: true,
h1: true, h2: true, h3: true, h4: true, h5: true, h6: true, cite: true,