Updated Rector to commit 7f8f9f818e7abf6e55a10648440d4079b4f5803f

7f8f9f818e [Core] Improve performance on AstResolver and ClassLikeAstResolver (#3234)
This commit is contained in:
Tomas Votruba 2022-12-22 11:35:32 +00:00
parent efb1e95fb5
commit 67958340fd
10 changed files with 55 additions and 35 deletions

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '84faf2905518aad5fb97caf613517f8a50827867';
public const PACKAGE_VERSION = '7f8f9f818e7abf6e55a10648440d4079b4f5803f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-12-21 14:13:24';
public const RELEASE_DATE = '2022-12-22 12:31:19';
/**
* @var int
*/

View File

@ -126,8 +126,14 @@ final class AstResolver
public function resolveClassMethodFromMethodReflection(MethodReflection $methodReflection) : ?ClassMethod
{
$classReflection = $methodReflection->getDeclaringClass();
if (isset($this->classMethodsByClassAndMethod[$classReflection->getName()][$methodReflection->getName()])) {
return $this->classMethodsByClassAndMethod[$classReflection->getName()][$methodReflection->getName()];
$classLikeName = $classReflection->getName();
$methodName = $methodReflection->getName();
if (isset($this->classMethodsByClassAndMethod[$classLikeName][$methodName])) {
return $this->classMethodsByClassAndMethod[$classLikeName][$methodName];
}
// saved as null data
if (\array_key_exists($classLikeName, $this->classMethodsByClassAndMethod) && \array_key_exists($methodName, $this->classMethodsByClassAndMethod[$classLikeName])) {
return null;
}
$fileName = $classReflection->getFileName();
// probably native PHP method → un-parseable
@ -140,21 +146,19 @@ final class AstResolver
}
/** @var ClassLike[] $classLikes */
$classLikes = $this->betterNodeFinder->findInstanceOf($nodes, ClassLike::class);
$classLikeName = $classReflection->getName();
$methodReflectionName = $methodReflection->getName();
foreach ($classLikes as $classLike) {
if (!$this->nodeNameResolver->isName($classLike, $classLikeName)) {
continue;
}
$classMethod = $classLike->getMethod($methodReflectionName);
$classMethod = $classLike->getMethod($methodName);
if (!$classMethod instanceof ClassMethod) {
continue;
}
$this->classMethodsByClassAndMethod[$classLikeName][$methodReflectionName] = $classMethod;
$this->classMethodsByClassAndMethod[$classLikeName][$methodName] = $classMethod;
return $classMethod;
}
// avoids looking for a class in a file where is not present
$this->classMethodsByClassAndMethod[$classLikeName][$methodReflectionName] = null;
$this->classMethodsByClassAndMethod[$classLikeName][$methodName] = null;
return null;
}
/**
@ -170,8 +174,13 @@ final class AstResolver
}
public function resolveFunctionFromFunctionReflection(FunctionReflection $functionReflection) : ?Function_
{
if (isset($this->functionsByName[$functionReflection->getName()])) {
return $this->functionsByName[$functionReflection->getName()];
$functionName = $functionReflection->getName();
if (isset($this->functionsByName[$functionName])) {
return $this->functionsByName[$functionName];
}
// saved as null data
if (\array_key_exists($functionName, $this->functionsByName)) {
return null;
}
$fileName = $functionReflection->getFileName();
if ($fileName === null) {
@ -184,15 +193,15 @@ final class AstResolver
/** @var Function_[] $functions */
$functions = $this->betterNodeFinder->findInstanceOf($nodes, Function_::class);
foreach ($functions as $function) {
if (!$this->nodeNameResolver->isName($function, $functionReflection->getName())) {
if (!$this->nodeNameResolver->isName($function, $functionName)) {
continue;
}
// to avoid parsing missing function again
$this->functionsByName[$functionReflection->getName()] = $function;
$this->functionsByName[$functionName] = $function;
return $function;
}
// to avoid parsing missing function again
$this->functionsByName[$functionReflection->getName()] = null;
$this->functionsByName[$functionName] = null;
return null;
}
/**

View File

@ -54,6 +54,10 @@ final class ClassLikeAstResolver
if (isset($this->classLikesByName[$className])) {
return $this->classLikesByName[$className];
}
// saved as null data
if (\array_key_exists($className, $this->classLikesByName)) {
return null;
}
$fileName = $classReflection->getFileName();
// probably internal class
if ($fileName === null) {

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921::getLoader();
return ComposerAutoloaderInit6e2562579b53b4d5b356013eb580354b::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921
class ComposerAutoloaderInit6e2562579b53b4d5b356013eb580354b
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6e2562579b53b4d5b356013eb580354b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6e2562579b53b4d5b356013eb580354b', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6e2562579b53b4d5b356013eb580354b::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit6e2562579b53b4d5b356013eb580354b::$files;
$requireFile = static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921
class ComposerStaticInit6e2562579b53b4d5b356013eb580354b
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3061,9 +3061,9 @@ class ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6e2562579b53b4d5b356013eb580354b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6e2562579b53b4d5b356013eb580354b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6e2562579b53b4d5b356013eb580354b::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2122,12 +2122,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "c5289ee54e37ac071e93fe3b0ac454619ed78ec8"
"reference": "b463377817b8d27fbf97c4d576bea9abf31b8261"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c5289ee54e37ac071e93fe3b0ac454619ed78ec8",
"reference": "c5289ee54e37ac071e93fe3b0ac454619ed78ec8",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/b463377817b8d27fbf97c4d576bea9abf31b8261",
"reference": "b463377817b8d27fbf97c4d576bea9abf31b8261",
"shasum": ""
},
"require": {
@ -2157,7 +2157,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2022-12-21T16:38:42+00:00",
"time": "2022-12-22T08:18:32+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a236bc6'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c5289ee'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a236bc6'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b463377'));
private function __construct()
{
}

View File

@ -117,11 +117,8 @@ CODE_SAMPLE
if (!$node instanceof Return_) {
return null;
}
if ($node->expr instanceof Expr) {
$returnedType = $this->getType($node->expr);
if ($returnedType instanceof IntegerType) {
return null;
}
if ($this->isReturnIntegerType($node->expr)) {
return null;
}
if ($node->expr instanceof Ternary && $this->isIntegerTernaryIfElse($node->expr)) {
$hasReturn = \true;
@ -137,6 +134,16 @@ CODE_SAMPLE
});
$this->processReturn0ToMethod($hasReturn, $classMethod);
}
private function isReturnIntegerType(?Expr $expr) : bool
{
if ($expr instanceof Expr) {
$returnedType = $this->getType($expr);
if ($returnedType instanceof IntegerType) {
return \true;
}
}
return \false;
}
private function isIntegerTernaryIfElse(Ternary $ternary) : bool
{
/** @var Expr|null $if */