mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Merge "Improve performance: remove redundant inputPreparation calls"
This commit is contained in:
commit
db160076f0
|
@ -22,12 +22,14 @@ use MediaWiki\Extension\Math\TexVC\Nodes\TexNode;
|
|||
*/
|
||||
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 ) ) {
|
||||
// just discard these elements, sometimes empty TexArray
|
||||
return null;
|
||||
}
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
if ( $prepareInput ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
}
|
||||
|
||||
// Checking for a named parsing function
|
||||
$resFct = BaseMappings::getMacroByKey( $input );
|
||||
|
@ -68,8 +70,11 @@ class BaseMethods {
|
|||
}
|
||||
}
|
||||
|
||||
public function checkAndParseOperator( $input, $node, $passedArgs, $operatorContent, $state ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
public function checkAndParseOperator( $input, $node, $passedArgs, $operatorContent,
|
||||
$state, $prepareInput = true ) {
|
||||
if ( $prepareInput ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
}
|
||||
$resOperator = BaseMappings::getOperatorByKey( $input );
|
||||
if ( $resOperator == null ) {
|
||||
|
||||
|
@ -143,8 +148,10 @@ class BaseMethods {
|
|||
return str_replace( "texClass", "data-mjx-texclass", $text );
|
||||
}
|
||||
|
||||
public function checkAndParseIdentifier( $input, $node, $passedArgs, $operatorContent ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
public function checkAndParseIdentifier( $input, $node, $passedArgs, $operatorContent, $prepareInput = true ) {
|
||||
if ( $prepareInput ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
}
|
||||
$resIdentifier = BaseMappings::getIdentifierByKey( $input );
|
||||
if ( $resIdentifier == null ) {
|
||||
$resIdentifier = AMSMappings::getIdentifierByKey( $input );
|
||||
|
@ -207,9 +214,11 @@ class BaseMethods {
|
|||
return $mo->encapsulateRaw( $resDelimiter[0] );
|
||||
}
|
||||
|
||||
public function checkAndParseMathCharacter( $input, $node, $passedArgs, $operatorContent ) {
|
||||
$inputP = MMLutil::inputPreparation( $input );
|
||||
$resChar = BaseMappings::getCharacterByKey( $inputP );
|
||||
public function checkAndParseMathCharacter( $input, $node, $passedArgs, $operatorContent, $prepareInput = true ) {
|
||||
if ( $prepareInput ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
}
|
||||
$resChar = BaseMappings::getCharacterByKey( $input );
|
||||
if ( $resChar == null ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -222,13 +231,15 @@ class BaseMethods {
|
|||
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
|
||||
if ( $operatorContent == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
if ( $prepareInput ) {
|
||||
$input = MMLutil::inputPreparation( $input );
|
||||
}
|
||||
if ( !( $input === 'color' || $input === 'pagecolor' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -50,21 +50,24 @@ class Literal extends TexNode {
|
|||
$mi = new MMLmi();
|
||||
return $mi->encapsulateRaw( $operatorContent );
|
||||
}
|
||||
|
||||
$inputP = MMLutil::inputPreparation( $input );
|
||||
|
||||
// Sieve for Operators
|
||||
$bm = new BaseMethods();
|
||||
$ret = $bm->checkAndParseOperator( $input, $this, $arguments, $operatorContent, $state );
|
||||
$ret = $bm->checkAndParseOperator( $inputP, $this, $arguments, $operatorContent, $state, false );
|
||||
if ( $ret ) {
|
||||
return $ret;
|
||||
}
|
||||
// Sieve for mathchar07 chars
|
||||
$bm = new BaseMethods();
|
||||
$ret = $bm->checkAndParseMathCharacter( $input, $this, $arguments, $operatorContent );
|
||||
$ret = $bm->checkAndParseMathCharacter( $inputP, $this, $arguments, $operatorContent, false );
|
||||
if ( $ret ) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// Sieve for Identifiers
|
||||
$ret = $bm->checkAndParseIdentifier( $input, $this, $arguments, $operatorContent );
|
||||
$ret = $bm->checkAndParseIdentifier( $inputP, $this, $arguments, $operatorContent, false );
|
||||
if ( $ret ) {
|
||||
return $ret;
|
||||
}
|
||||
|
@ -75,7 +78,7 @@ class Literal extends TexNode {
|
|||
}
|
||||
|
||||
// Sieve for Makros
|
||||
$ret = BaseMethods::checkAndParse( $input, $arguments, $operatorContent, $this );
|
||||
$ret = BaseMethods::checkAndParse( $inputP, $arguments, $operatorContent, $this, false );
|
||||
if ( $ret ) {
|
||||
return $ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue