Pastakhov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151810
Change subject: add PhpTags::$bytecodeCache (v 3.0.0)
......................................................................
add PhpTags::$bytecodeCache (v 3.0.0)
Change-Id: Iaa03ad5dba19279bcea0f1c7942c3e041bb39793
---
M PhpTags.body.php
M PhpTags.php
2 files changed, 42 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTags
refs/changes/10/151810/1
diff --git a/PhpTags.body.php b/PhpTags.body.php
index 3309d51..faf797d 100644
--- a/PhpTags.body.php
+++ b/PhpTags.body.php
@@ -10,11 +10,14 @@
*/
class PhpTags {
+ const SYNTAX_RELIZE = 0;
+
static $DebugLoops = false;
static $compileTime = 0;
private static $frames=array();
private static $needInitRuntime = true;
+ private static $bytecodeCache = array();
/**
*
@@ -54,28 +57,31 @@
try {
$titleText = $frame->getTitle()->getPrefixedText();
- $compiler = new PhpTags\Compiler();
- $bytecode = $compiler->compile($command, $titleText);
-
- // self::$compileTime += microtime(true) - $time;
- self::$compileTime +=
$parser->mOutput->getTimeSinceStart('cpu') - $time;
-
$arguments = array( $titleText ) +
$frame->getArguments();
+ $scope = self::getScope( $frame );
+ $md5 = md5( $command );
- $result = \PhpTags\Runtime::run(
- $bytecode,
- $arguments,
- self::getScope( $frame )
- );
+ if ( true === isset( self::$bytecodeCache[$scope][$md5]
) ) {
+ $bytecode = self::$bytecodeCache[$scope][$md5];
+ } else {
+ $compiler = new PhpTags\Compiler();
+ $bytecode = $compiler->compile( $command,
$titleText );
+ self::$bytecodeCache[$scope][$md5] = $bytecode;
+
+ // self::$compileTime += microtime(true) -
$time;
+ self::$compileTime +=
$parser->mOutput->getTimeSinceStart( 'cpu' ) - $time;
+ }
+
+ $result = \PhpTags\Runtime::run( $bytecode, $arguments,
$scope );
$return = implode( $result );
- } catch (\PhpTags\PhpTagsException $exc) {
+ } catch ( \PhpTags\PhpTagsException $exc ) {
$return = (string) $exc;
- } catch (Exception $exc) {
+ } catch ( Exception $exc ) {
$return = $exc->getTraceAsString();
}
// $wgPhpTagsTime += microtime(true) - $time;
- $wgPhpTagsTime += $parser->mOutput->getTimeSinceStart('cpu') -
$time;
+ $wgPhpTagsTime += $parser->mOutput->getTimeSinceStart( 'cpu' )
- $time;
return \UtfNormal::cleanUp($return);
}
@@ -84,10 +90,10 @@
global $wgPhpTagsTime, $wgPhpTagsMaxLoops;
//$time = microtime(true);
- $time = $parser->mOutput->getTimeSinceStart('cpu');
+ $time = $parser->mOutput->getTimeSinceStart( 'cpu' );
- $is_banned = self::isBanned($frame);
- if ( $is_banned ) {
+ $is_banned = self::isBanned( $frame );
+ if ( false !== $is_banned ) {
return $is_banned;
}
@@ -103,19 +109,22 @@
try {
$titleText = $frame->getTitle()->getPrefixedText();
- $compiler = new PhpTags\Compiler();
- $bytecode = $compiler->compile($input, $titleText);
-
- // self::$compileTime += microtime(true) - $time;
- self::$compileTime +=
$parser->mOutput->getTimeSinceStart('cpu') - $time;
-
$arguments = array( $titleText ) +
$frame->getArguments();
+ $scope = self::getScope( $frame );
+ $md5 = md5( $input );
- $result = \PhpTags\Runtime::run(
- $bytecode,
- $arguments,
- self::getScope( $frame )
- );
+ if ( true === isset( self::$bytecodeCache[$scope][$md5]
) ) {
+ $bytecode = self::$bytecodeCache[$scope][$md5];
+ } else {
+ $compiler = new PhpTags\Compiler();
+ $bytecode = $compiler->compile( $input,
$titleText );
+ self::$bytecodeCache[$scope][$md5] = $bytecode;
+
+ // self::$compileTime += microtime(true) -
$time;
+ self::$compileTime +=
$parser->mOutput->getTimeSinceStart( 'cpu' ) - $time;
+ }
+
+ $result = \PhpTags\Runtime::run( $bytecode, $arguments,
$scope );
} catch ( \PhpTags\PhpTagsException $exc ) {
// $wgPhpTagsTime += microtime(true) - $time;
$wgPhpTagsTime +=
$parser->mOutput->getTimeSinceStart('cpu') - $time;
@@ -129,7 +138,7 @@
// $wgPhpTagsTime += microtime(true) - $time;
$wgPhpTagsTime += $parser->mOutput->getTimeSinceStart('cpu') -
$time;
- if( count($result) > 0 ) {
+ if( true === isset( $result[0] ) ) {
//$return .=
Sanitizer::removeHTMLtags(implode($result));
$return .= self::insertGeneral(
$parser,
@@ -144,7 +153,7 @@
*
* @global type $wgPhpTagsNamespaces
* @param PPFrame $frame
- * @return boolean
+ * @return mixed
*/
public static function isBanned( PPFrame $frame ) {
global $wgPhpTagsNamespaces;
diff --git a/PhpTags.php b/PhpTags.php
index daaa51c..e068e90 100644
--- a/PhpTags.php
+++ b/PhpTags.php
@@ -15,9 +15,9 @@
die( 'This file is an extension to MediaWiki and thus not a valid entry
point.' );
}
-define( 'PHPTAGS_MAJOR_VERSION', 2 );
-define( 'PHPTAGS_MINOR_VERSION', 8 );
-define( 'PHPTAGS_RELEASE_VERSION', 5 );
+define( 'PHPTAGS_MAJOR_VERSION', 3 );
+define( 'PHPTAGS_MINOR_VERSION', 0 );
+define( 'PHPTAGS_RELEASE_VERSION', 0 );
define( 'PHPTAGS_VERSION', PHPTAGS_MAJOR_VERSION . '.' . PHPTAGS_MINOR_VERSION
. '.' . PHPTAGS_RELEASE_VERSION );
define( 'PHPTAGS_HOOK_RELEASE', 4 );
--
To view, visit https://gerrit.wikimedia.org/r/151810
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa03ad5dba19279bcea0f1c7942c3e041bb39793
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PhpTags
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits