Updated Rector to commit 2766aa8ac4a273b0d0a6e0869eb71eca428fcaf0

2766aa8ac4 [Performance] Reduce repetitive parent lookup on BetterNodeFinder::findFirstNext() by inline search when possible (#3885)
This commit is contained in:
Tomas Votruba 2023-05-18 15:08:46 +00:00
parent 1d3c5ccdb3
commit d977ea6b6f
7 changed files with 56 additions and 32 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b0649221240ae8a57862290534f9cb05135ac018';
public const PACKAGE_VERSION = '2766aa8ac4a273b0d0a6e0869eb71eca428fcaf0';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-18 21:14:33';
public const RELEASE_DATE = '2023-05-18 22:04:49';
/**
* @var int
*/

View File

@ -0,0 +1,9 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Exception;
use Exception;
final class StopSearchException extends Exception
{
}

View File

@ -30,6 +30,7 @@ use PhpParser\Node\Stmt\While_;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Exception\StopSearchException;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
@ -333,16 +334,15 @@ final class BetterNodeFinder
public function findFirstNext(Node $node, callable $filter) : ?Node
{
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
$nextNode = $this->resolveNextNode($node, $parentNode);
if ($nextNode instanceof Node) {
if ($nextNode instanceof Return_ && !$nextNode->expr instanceof Expr && !$parentNode instanceof Case_) {
return null;
}
$found = $this->findFirst($nextNode, $filter);
if ($found instanceof Node) {
return $found;
}
return $this->findFirstNext($nextNode, $filter);
$newStmts = $this->resolveNewStmts($parentNode);
try {
$foundNode = $this->findFirstInlinedNext($node, $filter, $newStmts, $parentNode);
} catch (StopSearchException $exception) {
return null;
}
// we found what we need
if ($foundNode instanceof Node) {
return $foundNode;
}
if ($parentNode instanceof Return_ || $parentNode instanceof FunctionLike) {
return null;
@ -478,24 +478,37 @@ final class BetterNodeFinder
}
return null;
}
private function resolveNextNode(Node $node, ?Node $parentNode) : ?Node
/**
* Only search in next Node/Stmt
*
* @param Stmt[] $newStmts
* @param callable(Node $node): bool $filter
*/
private function findFirstInlinedNext(Node $node, callable $filter, array $newStmts, ?Node $parentNode) : ?Node
{
if (!$parentNode instanceof Node) {
$newStmts = $this->resolveNewStmts($parentNode);
return $this->resolveNodeFromFile($newStmts, $node, \false);
}
if ($node instanceof Stmt) {
$nextNode = $this->resolveNodeFromFile($newStmts, $node, \false);
} elseif ($node instanceof Stmt) {
if (!$parentNode instanceof StmtsAwareInterface) {
return null;
}
if ($parentNode->stmts === null) {
return null;
}
// todo: use +1 key once all next node attribute reference and NodeConnectingVisitor removed
// left with add SlimNodeConnectingVisitor for only lookup parent
return $node->getAttribute(AttributeKey::NEXT_NODE);
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
} else {
$nextNode = $this->resolveNextNodeFromOtherNode($node);
}
return $this->resolveNextNodeFromOtherNode($node);
if (!$nextNode instanceof Node) {
return null;
}
if ($nextNode instanceof Return_ && !$nextNode->expr instanceof Expr && !$parentNode instanceof Case_) {
throw new StopSearchException();
}
$found = $this->findFirst($nextNode, $filter);
if ($found instanceof Node) {
return $found;
}
return $this->findFirstInlinedNext($nextNode, $filter, $newStmts, $parentNode);
}
/**
* @return Stmt[]

2
vendor/autoload.php vendored
View File

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

View File

@ -1437,6 +1437,7 @@ return array(
'Rector\\Core\\Exception\\Reflection\\InvalidPrivatePropertyTypeException' => $baseDir . '/src/Exception/Reflection/InvalidPrivatePropertyTypeException.php',
'Rector\\Core\\Exception\\Reflection\\MissingPrivatePropertyException' => $baseDir . '/src/Exception/Reflection/MissingPrivatePropertyException.php',
'Rector\\Core\\Exception\\ShouldNotHappenException' => $baseDir . '/src/Exception/ShouldNotHappenException.php',
'Rector\\Core\\Exception\\StopSearchException' => $baseDir . '/src/Exception/StopSearchException.php',
'Rector\\Core\\Exception\\VersionException' => $baseDir . '/src/Exception/VersionException.php',
'Rector\\Core\\FileSystem\\FileAndDirectoryFilter' => $baseDir . '/src/FileSystem/FileAndDirectoryFilter.php',
'Rector\\Core\\FileSystem\\FilePathHelper' => $baseDir . '/src/FileSystem/FilePathHelper.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3f1ddc210878d1ed27b647798f3d882f
class ComposerAutoloaderInit776e005b801980c9063d26a20bc95ed1
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit3f1ddc210878d1ed27b647798f3d882f
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3f1ddc210878d1ed27b647798f3d882f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit776e005b801980c9063d26a20bc95ed1', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit3f1ddc210878d1ed27b647798f3d882f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit776e005b801980c9063d26a20bc95ed1', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit776e005b801980c9063d26a20bc95ed1::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit776e005b801980c9063d26a20bc95ed1::$files;
$requireFile = \Closure::bind(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 ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f
class ComposerStaticInit776e005b801980c9063d26a20bc95ed1
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1679,6 +1679,7 @@ class ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f
'Rector\\Core\\Exception\\Reflection\\InvalidPrivatePropertyTypeException' => __DIR__ . '/../..' . '/src/Exception/Reflection/InvalidPrivatePropertyTypeException.php',
'Rector\\Core\\Exception\\Reflection\\MissingPrivatePropertyException' => __DIR__ . '/../..' . '/src/Exception/Reflection/MissingPrivatePropertyException.php',
'Rector\\Core\\Exception\\ShouldNotHappenException' => __DIR__ . '/../..' . '/src/Exception/ShouldNotHappenException.php',
'Rector\\Core\\Exception\\StopSearchException' => __DIR__ . '/../..' . '/src/Exception/StopSearchException.php',
'Rector\\Core\\Exception\\VersionException' => __DIR__ . '/../..' . '/src/Exception/VersionException.php',
'Rector\\Core\\FileSystem\\FileAndDirectoryFilter' => __DIR__ . '/../..' . '/src/FileSystem/FileAndDirectoryFilter.php',
'Rector\\Core\\FileSystem\\FilePathHelper' => __DIR__ . '/../..' . '/src/FileSystem/FilePathHelper.php',
@ -3113,9 +3114,9 @@ class ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3f1ddc210878d1ed27b647798f3d882f::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit776e005b801980c9063d26a20bc95ed1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit776e005b801980c9063d26a20bc95ed1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit776e005b801980c9063d26a20bc95ed1::$classMap;
}, null, ClassLoader::class);
}