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:
thiemowmde 2022-12-01 16:15:22 +01:00
parent af92f38bbf
commit 89941febb4

View file

@ -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 );
}
/**