Minor cleanup

Change-Id: Ic81ab852c43e98370097d01c3b6d6cddee7a5850
This commit is contained in:
Reedy 2022-04-16 22:09:10 +01:00
parent 2573ae2fd8
commit 6f411e3921
19 changed files with 38 additions and 53 deletions

View file

@ -130,7 +130,7 @@ class ScribuntoHooks {
if ( $u1 > $u0 ) {
$timingMs = (int)( 1000 * ( $u1 - $u0 ) );
// Since the overhead of stats is worst when when #invoke
// Since the overhead of stats is worst when #invoke
// calls are very short, don't process measurements <= 20ms.
if ( $timingMs > 20 ) {
self::reportTiming( $moduleName, $functionName, $timingMs );
@ -215,7 +215,7 @@ class ScribuntoHooks {
// This is a classic "read-update-write" critical section with no
// mutual exclusion, but the only consequence is that some samples
// will be dropped. We only need enough samples to estimate the
// the shape of the data, so that's fine.
// shape of the data, so that's fine.
$ps = $cache->get( $key ) ?: new PSquare( $threshold );
$ps->addObservation( $timing );
$cache->set( $key, $ps, 60 );

View file

@ -408,7 +408,6 @@ class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
$this->checkTypeOptional( 'formatDuration', 2, $args[1], 'table', [] );
list( $seconds, $chosenIntervals ) = $args;
$langcode = $lang->getCode();
$chosenIntervals = array_values( $chosenIntervals );
$ret = $lang->formatDuration( $seconds, $chosenIntervals );
@ -427,7 +426,6 @@ class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
$this->checkTypeOptional( 'getDurationIntervals', 2, $args[1], 'table', [] );
list( $seconds, $chosenIntervals ) = $args;
$langcode = $lang->getCode();
$chosenIntervals = array_values( $chosenIntervals );
$ret = $lang->getDurationIntervals( $seconds, $chosenIntervals );

View file

@ -36,15 +36,11 @@ class Scribunto_LuaError extends ScribuntoException {
if ( !isset( $this->params['trace'] ) ) {
return false;
}
if ( isset( $options['msgOptions'] ) ) {
$msgOptions = $options['msgOptions'];
} else {
$msgOptions = [];
}
$msgOptions = $options['msgOptions'] ?? [];
$s = '<ol class="scribunto-trace">';
foreach ( $this->params['trace'] as $info ) {
$short_src = $srcdefined = $info['short_src'];
$short_src = $info['short_src'];
$currentline = $info['currentline'];
$src = htmlspecialchars( $short_src );

View file

@ -66,10 +66,6 @@ class Scribunto_LuaModule extends ScribuntoModuleBase {
}
$result = $this->engine->executeFunctionChunk( $ret, $frame );
if ( isset( $result[0] ) ) {
return $result[0];
} else {
return null;
}
return $result[0] ?? null;
}
}

View file

@ -191,7 +191,7 @@ class Scribunto_LuaSiteLibrary extends Scribunto_LuaLibraryBase {
"bad argument #1 to 'interwikiMap' (unknown filter '$filter')"
);
}
$cacheKey = $filter === null ? 'null' : $filter;
$cacheKey = $filter ?? 'null';
if ( !isset( self::$interwikiMapCache[$cacheKey] ) ) {
// Not expensive because we can have a max of three cache misses in the
// entire page parse.

View file

@ -173,7 +173,7 @@ class Scribunto_LuaTitleLibrary extends Scribunto_LuaLibraryBase {
$this->idCache[$text_or_id] = $title;
// Record a link
if ( $this->getParser() && $title && !$title->equals( $this->getTitle() ) ) {
if ( $title && $this->getParser() && !$title->equals( $this->getTitle() ) ) {
$this->getParser()->getOutput()->addLink( $title );
}
}

View file

@ -911,7 +911,7 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
$count = 0;
$s2 = preg_replace_callback( $re, $cb, $s, $n, $count );
if ( $s2 === null ) {
self::handlePCREError( preg_last_error(), $pattern );
$this->handlePCREError( preg_last_error(), $pattern );
}
return [ $s2, $count - $skippedMatches ];
}

View file

@ -17,7 +17,7 @@ Visit http://luaforge.net/projects/bit/ to get latest version.
Status
------
Now LuaBit is in v0.4.
Now LuaBit is in v0.4.
Release date: Mar 18, 2007
Content
@ -27,14 +27,14 @@ Content
is the bitwise operation lib, all operations are implemented here.
2) hex.lua
is a helper lib for ease of using hex numbers with bitwise
is a helper lib for ease of using hex numbers with bitwise
operation.
3) noki.lua
a utility(based on bit and hex) to convert Nokia PC Suite backuped
SMS to a unicode .txt file, which is more accessible than the
a utility(based on bit and hex) to convert Nokia PC Suite backuped
SMS to a unicode .txt file, which is more accessible than the
original .nfb or .nfc file.
4) utf8.lua
convert utf8 string to ucs2 string
@ -42,7 +42,7 @@ How to use
----------
Bit
---
Just require 'bit' in your project and the bit lib will be
Just require 'bit' in your project and the bit lib will be
available:
bit.bnot(n) -- bitwise not (~n)
bit.band(m, n) -- bitwise and (m & n)
@ -58,11 +58,11 @@ Please note that bit.brshift and bit.blshift only support number within
2 utility functions are provided too:
bit.tobits(n) -- convert n into a bit table(which is a 1/0 sequence)
-- high bits first
bit.tonumb(bit_tbl) -- convert a bit table into a number
bit.tonumb(bit_tbl) -- convert a bit table into a number
Hex
---
For ease of using hex numbers, a utility hex lib is also included in
For ease of using hex numbers, a utility hex lib is also included in
LuaBit. You can require 'hex' to use them:
hex.to_hex(n) -- convert a number to a hex string
hex.to_dec(hex) -- convert a hex string(prefix with '0x' or '0X') to number
@ -100,7 +100,7 @@ v0.2
* update hex.to_hex(in hex.lua) to support negative number.
v0.1
LuaBit is written when I do my own game project(Fio at http://fio.edithis.info).
LuaBit is written when I do my own game project(Fio at http://fio.edithis.info).
When loading resources, I have to do some bit operation. And I do not
like the embedded way of bit operation. So I decide to implement those
ops in lua. And that's LuaBit. It's not as fast as the embedded one, but
@ -114,7 +114,7 @@ It'll be useful if LuaBit support those bitwise op like:
ease to type and use. This will be supported in next release.
v0.2
I decide to delay this feature to later version for it'll mess up the
I decide to delay this feature to later version for it'll mess up the
interface of LuaBit.
v0.3
@ -125,19 +125,19 @@ There's no UCS2 -> UTF8 convertion now, this feature may add in next release
or when the project need.
Noki'll be be exluded from LuaBit in next release; I decide to let Noki grow
into a powerful tool to support more Nokia PC Suite backup format(.nfb,
.nfc and .nbu).
into a powerful tool to support more Nokia PC Suite backup format(.nfb,
.nfc and .nbu).
Trial Noki demo at http://nokisms.googlepages.com/(in Chinese)
Known issues
------------
LuaBit doesn't play very well with negative number. The return value of the
bitwise operations might change to positive when applied on negative numbers
bitwise operations might change to positive when applied on negative numbers
though the bit sequence is correct. So if you want do some arithmetic with
the result of bit operation, be careful.
Feedback
--------
Please send your comments, bugs, patches or change request to
Please send your comments, bugs, patches or change request to
hanzhao(abrash_han@hotmail.com).

View file

@ -107,11 +107,9 @@ foreach ( $pats as $k => $pp ) {
if ( $rstart === null ) {
$rstart = $i;
}
} else {
if ( $rstart !== null ) {
addRange( $k, $rstart, $i );
$rstart = null;
}
} elseif ( $rstart !== null ) {
addRange( $k, $rstart, $i );
$rstart = null;
}
}
if ( $rstart !== null ) {

View file

@ -152,8 +152,6 @@ class Scribunto_LuaSandboxEngine extends Scribunto_LuaEngine {
* @suppress SecurityCheck-DoubleEscaped phan false positive
*/
public function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
global $wgLang;
$lang = $localize ? $wgLang : Language::factory( 'en' );
switch ( $key ) {
case 'scribunto-limitreport-logs':
if ( $isHTML ) {

View file

@ -65,8 +65,6 @@ class Scribunto_LuaStandaloneEngine extends Scribunto_LuaEngine {
/** @inheritDoc */
public function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
global $wgLang;
$lang = $localize ? $wgLang : Language::factory( 'en' );
switch ( $key ) {
case 'scribunto-limitreport-logs':
if ( $isHTML ) {

View file

@ -469,7 +469,7 @@ class Scribunto_LuaCommonTest extends Scribunto_LuaEngineTestBase {
// Test calling a non-existent function
try {
$ret = $engine->runConsole( [
$engine->runConsole( [
'question' => '=mw.getCurrentFrame():callParserFunction{
name = "thisDoesNotExist", args = { "" }
}',

View file

@ -1,5 +1,7 @@
<?php
use PHPUnit\Framework\TestSuite;
/**
* This is the subclass for Lua library tests. It will automatically run all
* tests against LuaSandbox and LuaStandalone.
@ -64,7 +66,7 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiLangTestCase {
/**
* Create a PHPUnit test suite to run the test against all engines
* @param string $className Test class name
* @return \PHPUnit\Framework\TestSuite
* @return TestSuite
*/
public static function suite( $className ) {
return self::makeSuite( $className );

View file

@ -1,5 +1,8 @@
<?php
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
/**
* This is the subclass for Lua library tests. It will automatically run all
* tests against LuaSandbox and LuaStandalone.
@ -9,7 +12,7 @@
* - getTestModules(): Add a mapping from $moduleName to the file containing
* the code.
*/
abstract class Scribunto_LuaEngineUnitTestBase extends \PHPUnit\Framework\TestCase {
abstract class Scribunto_LuaEngineUnitTestBase extends TestCase {
use MediaWikiCoversValidator;
use Scribunto_LuaEngineTestHelper;
@ -65,7 +68,7 @@ abstract class Scribunto_LuaEngineUnitTestBase extends \PHPUnit\Framework\TestCa
/**
* Create a PHPUnit test suite to run the test against all engines
* @param string $className Test class name
* @return \PHPUnit\Framework\TestSuite
* @return TestSuite
*/
public static function suite( $className ) {
return self::makeSuite( $className );

View file

@ -50,7 +50,6 @@ class Scribunto_LuaEnvironmentComparisonTest extends PHPUnit\Framework\TestCase
);
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
$this->markTestSkipped( "LuaSandbox interpreter not available" );
return;
}
try {
@ -59,7 +58,6 @@ class Scribunto_LuaEnvironmentComparisonTest extends PHPUnit\Framework\TestCase
);
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
$this->markTestSkipped( "LuaStandalone interpreter not available" );
return;
}
}

View file

@ -19,7 +19,7 @@ abstract class Scribunto_LuaInterpreterTest extends PHPUnit\Framework\TestCase {
}
protected function getBusyLoop( $interpreter ) {
$chunk = $interpreter->loadString( '
return $interpreter->loadString( '
local args = {...}
local x, i
local s = string.rep("x", 1000000)
@ -30,7 +30,6 @@ abstract class Scribunto_LuaInterpreterTest extends PHPUnit\Framework\TestCase {
if e and os.clock() >= e then break end
end',
'busy' );
return $chunk;
}
/** @dataProvider provideRoundtrip */

View file

@ -41,7 +41,7 @@ class Scribunto_LuaTitleLibraryTest extends Scribunto_LuaEngineTestBase {
] ),
] );
$editor = $this->getTestSysop()->getUser();
$editor = self::getTestSysop()->getUser();
$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();

View file

@ -19,7 +19,7 @@ class Scribunto_LuaSandboxInterpreterTest extends Scribunto_LuaInterpreterTest {
];
protected function newInterpreter( $opts = [] ) {
$opts = $opts + $this->stdOpts;
$opts += $this->stdOpts;
$engine = new Scribunto_LuaSandboxEngine( $this->stdOpts );
return new Scribunto_LuaSandboxInterpreter( $engine, $opts );
}

View file

@ -29,7 +29,7 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
}
protected function newInterpreter( $opts = [] ) {
$opts = $opts + $this->stdOpts;
$opts += $this->stdOpts;
$engine = new Scribunto_LuaStandaloneEngine( $this->stdOpts );
return new Scribunto_LuaStandaloneInterpreter( $engine, $opts );
}
@ -62,7 +62,6 @@ class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTes
$startTime = microtime( true );
if ( php_uname( 's' ) !== 'Linux' ) {
$this->markTestSkipped( "getStatus() not supported on platforms other than Linux" );
return;
}
$interpreter = $this->newInterpreter();
$engine = TestingAccessWrapper::newFromObject( $interpreter->engine );