mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-28 01:10:09 +00:00
Merge "Fix Perfomance Issues of TexUtil"
This commit is contained in:
commit
3dcdbbd95b
|
@ -19,7 +19,7 @@ class Fun1 extends TexNode {
|
||||||
parent::__construct( $fname, $arg );
|
parent::__construct( $fname, $arg );
|
||||||
$this->fname = $fname;
|
$this->fname = $fname;
|
||||||
$this->arg = $arg;
|
$this->arg = $arg;
|
||||||
$this->tu = new TexUtil();
|
$this->tu = TexUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,8 +16,7 @@ class Literal extends TexNode {
|
||||||
public function __construct( string $arg ) {
|
public function __construct( string $arg ) {
|
||||||
parent::__construct( $arg );
|
parent::__construct( $arg );
|
||||||
$this->arg = $arg;
|
$this->arg = $arg;
|
||||||
$tu = new TexUtil();
|
$this->literals = array_keys( TexUtil::getInstance()->getBaseElements()['is_literal'] );
|
||||||
$this->literals = array_keys( $tu->getBaseElements()['is_literal'] );
|
|
||||||
$this->extendedLiterals = $this->literals;
|
$this->extendedLiterals = $this->literals;
|
||||||
array_push( $this->extendedLiterals, '\\infty', '\\emptyset' );
|
array_push( $this->extendedLiterals, '\\infty', '\\emptyset' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -9536,7 +9536,7 @@ class Parser {
|
||||||
|
|
||||||
/* BEGIN initializer code */
|
/* BEGIN initializer code */
|
||||||
|
|
||||||
$this->tu = new TexUtil();
|
$this->tu = TexUtil::getInstance();
|
||||||
# get reference of the options for usage in functions.
|
# get reference of the options for usage in functions.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace MediaWiki\Extension\Math\TexVC;
|
||||||
use MWException;
|
use MWException;
|
||||||
|
|
||||||
class TexUtil {
|
class TexUtil {
|
||||||
|
private static $instance = null;
|
||||||
private $allFunctions;
|
private $allFunctions;
|
||||||
private $baseElements;
|
private $baseElements;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ class TexUtil {
|
||||||
* allFunctions holds the root-level function keys
|
* allFunctions holds the root-level function keys
|
||||||
* other objects are second level elements and hold all functions which are assigned to this second level elements
|
* other objects are second level elements and hold all functions which are assigned to this second level elements
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
private function __construct() {
|
||||||
$jsonContent = $this->getJSON();
|
$jsonContent = $this->getJSON();
|
||||||
// dynamically create functions from the content
|
// dynamically create functions from the content
|
||||||
$this->allFunctions = [];
|
$this->allFunctions = [];
|
||||||
|
@ -41,6 +42,18 @@ class TexUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function removeInstance() {
|
||||||
|
self::$instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance() {
|
||||||
|
if ( self::$instance == null ) {
|
||||||
|
self::$instance = new TexUtil();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returning the base elements array.
|
* Returning the base elements array.
|
||||||
* This is only used for testing in TexUtilTest.php.
|
* This is only used for testing in TexUtilTest.php.
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TexVC {
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->parser = new Parser();
|
$this->parser = new Parser();
|
||||||
$this->tu = new TexUtil();
|
$this->tu = TexUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function strStartsWith( $haystack, $needle ): bool {
|
private function strStartsWith( $haystack, $needle ): bool {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/** PEGjs lexer/parser */
|
/** PEGjs lexer/parser */
|
||||||
{
|
{
|
||||||
$this->tu = new TexUtil();
|
$this->tu = TexUtil::getInstance();
|
||||||
|
|
||||||
# get reference of the options for usage in functions.
|
# get reference of the options for usage in functions.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@ use MediaWikiUnitTestCase;
|
||||||
class TexUtilTest extends MediaWikiUnitTestCase {
|
class TexUtilTest extends MediaWikiUnitTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic test for tex util.
|
* Basic test for TexUtil
|
||||||
*/
|
*/
|
||||||
public function testTexUtil() {
|
public function testTexUtil() {
|
||||||
$tu = new TexUtil();
|
TexUtil::removeInstance();
|
||||||
|
$tu = TexUtil::getInstance();
|
||||||
// Testing all functions
|
// Testing all functions
|
||||||
$this->assertTrue( $tu->getAllFunctionsAt( "\\AA" ) );
|
$this->assertTrue( $tu->getAllFunctionsAt( "\\AA" ) );
|
||||||
$this->assertFalse( $tu->getAllFunctionsAt( "\\notlisted" ) );
|
$this->assertFalse( $tu->getAllFunctionsAt( "\\notlisted" ) );
|
||||||
|
@ -28,7 +29,7 @@ class TexUtilTest extends MediaWikiUnitTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testChecksum() {
|
public function testChecksum() {
|
||||||
$tu = new TexUtil();
|
$tu = TexUtil::getInstance();
|
||||||
|
|
||||||
$out = [];
|
$out = [];
|
||||||
$sets = [
|
$sets = [
|
||||||
|
|
Loading…
Reference in a new issue