mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 11:48:23 +00:00
Minor preformance improvement in TexNode::texContainsFunc
This apparently doesn't make that much of a difference, but should still be worth it. Strings that don't start with a backslash can not match anything. We can stop much earlier in this case. Change-Id: I1efb8dc6807931a075f450c56f9bbd64980c879a
This commit is contained in:
parent
af92f38bbf
commit
89941febb4
|
@ -102,6 +102,11 @@ class TexNode {
|
|||
* @return string|bool rendered LaTeX string or false if not found.
|
||||
*/
|
||||
public static function texContainsFunc( $target, string $t ) {
|
||||
// protect against using random strings as keys in target
|
||||
if ( !$t || $t[0] !== '\\' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// may have trailing '(', '[', '\\{' or " "
|
||||
$t = preg_replace( '/(\(|\[|\\\\{| )$/', '', $t );
|
||||
|
||||
|
@ -132,12 +137,7 @@ class TexNode {
|
|||
return self::match( $target, $matches[1] ) ?: self::match( $target, $matches[2] );
|
||||
}
|
||||
|
||||
// protect against using random strings as keys in target
|
||||
if ( substr( $t, 0, 1 ) === '\\' ) {
|
||||
return self::match( $target, $t );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return self::match( $target, $t );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue