Merge "Improve performance: remove redundant inputPreparation calls"

This commit is contained in:
jenkins-bot 2023-03-31 09:27:46 +00:00 committed by Gerrit Code Review
commit db160076f0
2 changed files with 29 additions and 15 deletions

View file

@ -22,12 +22,14 @@ use MediaWiki\Extension\Math\TexVC\Nodes\TexNode;
*/ */
class BaseMethods { class BaseMethods {
public static function checkAndParse( $input, $passedArgs, $operatorContent, TexNode $node ) { public static function checkAndParse( $input, $passedArgs, $operatorContent, TexNode $node, $prepareInput = true ) {
if ( !is_string( $input ) ) { if ( !is_string( $input ) ) {
// just discard these elements, sometimes empty TexArray // just discard these elements, sometimes empty TexArray
return null; return null;
} }
$input = MMLutil::inputPreparation( $input ); if ( $prepareInput ) {
$input = MMLutil::inputPreparation( $input );
}
// Checking for a named parsing function // Checking for a named parsing function
$resFct = BaseMappings::getMacroByKey( $input ); $resFct = BaseMappings::getMacroByKey( $input );
@ -68,8 +70,11 @@ class BaseMethods {
} }
} }
public function checkAndParseOperator( $input, $node, $passedArgs, $operatorContent, $state ) { public function checkAndParseOperator( $input, $node, $passedArgs, $operatorContent,
$input = MMLutil::inputPreparation( $input ); $state, $prepareInput = true ) {
if ( $prepareInput ) {
$input = MMLutil::inputPreparation( $input );
}
$resOperator = BaseMappings::getOperatorByKey( $input ); $resOperator = BaseMappings::getOperatorByKey( $input );
if ( $resOperator == null ) { if ( $resOperator == null ) {
@ -143,8 +148,10 @@ class BaseMethods {
return str_replace( "texClass", "data-mjx-texclass", $text ); return str_replace( "texClass", "data-mjx-texclass", $text );
} }
public function checkAndParseIdentifier( $input, $node, $passedArgs, $operatorContent ) { public function checkAndParseIdentifier( $input, $node, $passedArgs, $operatorContent, $prepareInput = true ) {
$input = MMLutil::inputPreparation( $input ); if ( $prepareInput ) {
$input = MMLutil::inputPreparation( $input );
}
$resIdentifier = BaseMappings::getIdentifierByKey( $input ); $resIdentifier = BaseMappings::getIdentifierByKey( $input );
if ( $resIdentifier == null ) { if ( $resIdentifier == null ) {
$resIdentifier = AMSMappings::getIdentifierByKey( $input ); $resIdentifier = AMSMappings::getIdentifierByKey( $input );
@ -207,9 +214,11 @@ class BaseMethods {
return $mo->encapsulateRaw( $resDelimiter[0] ); return $mo->encapsulateRaw( $resDelimiter[0] );
} }
public function checkAndParseMathCharacter( $input, $node, $passedArgs, $operatorContent ) { public function checkAndParseMathCharacter( $input, $node, $passedArgs, $operatorContent, $prepareInput = true ) {
$inputP = MMLutil::inputPreparation( $input ); if ( $prepareInput ) {
$resChar = BaseMappings::getCharacterByKey( $inputP ); $input = MMLutil::inputPreparation( $input );
}
$resChar = BaseMappings::getCharacterByKey( $input );
if ( $resChar == null ) { if ( $resChar == null ) {
return null; return null;
} }
@ -222,13 +231,15 @@ class BaseMethods {
return $mi->encapsulateRaw( $enc ); return $mi->encapsulateRaw( $enc );
} }
public function checkAndParseColor( $input, $node, $passedArgs, $operatorContent ) { public function checkAndParseColor( $input, $node, $passedArgs, $operatorContent, $prepareInput = true ) {
// tbd usually this encapsulates the succeeding box element // tbd usually this encapsulates the succeeding box element
if ( $operatorContent == null ) { if ( $operatorContent == null ) {
return null; return null;
} }
$input = MMLutil::inputPreparation( $input ); if ( $prepareInput ) {
$input = MMLutil::inputPreparation( $input );
}
if ( !( $input === 'color' || $input === 'pagecolor' ) ) { if ( !( $input === 'color' || $input === 'pagecolor' ) ) {
return null; return null;
} }

View file

@ -50,21 +50,24 @@ class Literal extends TexNode {
$mi = new MMLmi(); $mi = new MMLmi();
return $mi->encapsulateRaw( $operatorContent ); return $mi->encapsulateRaw( $operatorContent );
} }
$inputP = MMLutil::inputPreparation( $input );
// Sieve for Operators // Sieve for Operators
$bm = new BaseMethods(); $bm = new BaseMethods();
$ret = $bm->checkAndParseOperator( $input, $this, $arguments, $operatorContent, $state ); $ret = $bm->checkAndParseOperator( $inputP, $this, $arguments, $operatorContent, $state, false );
if ( $ret ) { if ( $ret ) {
return $ret; return $ret;
} }
// Sieve for mathchar07 chars // Sieve for mathchar07 chars
$bm = new BaseMethods(); $bm = new BaseMethods();
$ret = $bm->checkAndParseMathCharacter( $input, $this, $arguments, $operatorContent ); $ret = $bm->checkAndParseMathCharacter( $inputP, $this, $arguments, $operatorContent, false );
if ( $ret ) { if ( $ret ) {
return $ret; return $ret;
} }
// Sieve for Identifiers // Sieve for Identifiers
$ret = $bm->checkAndParseIdentifier( $input, $this, $arguments, $operatorContent ); $ret = $bm->checkAndParseIdentifier( $inputP, $this, $arguments, $operatorContent, false );
if ( $ret ) { if ( $ret ) {
return $ret; return $ret;
} }
@ -75,7 +78,7 @@ class Literal extends TexNode {
} }
// Sieve for Makros // Sieve for Makros
$ret = BaseMethods::checkAndParse( $input, $arguments, $operatorContent, $this ); $ret = BaseMethods::checkAndParse( $inputP, $arguments, $operatorContent, $this, false );
if ( $ret ) { if ( $ret ) {
return $ret; return $ret;
} }