Updated Rector to commit d8d31debc51ab5df1d30655846bb0fbd9f76039b

d8d31debc5 [Performance] Use more performance spl_object_id() (#4876)
This commit is contained in:
Tomas Votruba 2023-08-28 17:41:52 +00:00
parent de9ddf6e5d
commit 73a1ef4a72
11 changed files with 53 additions and 53 deletions

View File

@ -61,9 +61,9 @@ final class PhpDocInfoFactory
*/
private $phpDocNodeByTypeFinder;
/**
* @var array<string, PhpDocInfo>
* @var array<int, PhpDocInfo>
*/
private $phpDocInfosByObjectHash = [];
private $phpDocInfosByObjectId = [];
public function __construct(PhpDocNodeMapper $phpDocNodeMapper, CurrentNodeProvider $currentNodeProvider, Lexer $lexer, BetterPhpDocParser $betterPhpDocParser, StaticTypeMapper $staticTypeMapper, AnnotationNaming $annotationNaming, RectorChangeCollector $rectorChangeCollector, PhpDocNodeByTypeFinder $phpDocNodeByTypeFinder)
{
$this->phpDocNodeMapper = $phpDocNodeMapper;
@ -90,9 +90,9 @@ final class PhpDocInfoFactory
}
public function createFromNode(Node $node) : ?\Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo
{
$objectHash = \spl_object_hash($node);
if (isset($this->phpDocInfosByObjectHash[$objectHash])) {
return $this->phpDocInfosByObjectHash[$objectHash];
$objectId = \spl_object_id($node);
if (isset($this->phpDocInfosByObjectId[$objectId])) {
return $this->phpDocInfosByObjectId[$objectId];
}
/** @see \Rector\BetterPhpDocParser\PhpDocParser\DoctrineAnnotationDecorator::decorate() */
$this->currentNodeProvider->setNode($node);
@ -111,7 +111,7 @@ final class PhpDocInfoFactory
$this->setPositionOfLastToken($phpDocNode);
}
$phpDocInfo = $this->createFromPhpDocNode($phpDocNode, $tokenIterator, $node);
$this->phpDocInfosByObjectHash[$objectHash] = $phpDocInfo;
$this->phpDocInfosByObjectId[$objectId] = $phpDocInfo;
return $phpDocInfo;
}
/**

View File

@ -44,9 +44,9 @@ final class ClassAnnotationMatcher
}
public function resolveTagFullyQualifiedName(string $tag, Node $node) : string
{
$uniqueHash = $tag . \spl_object_hash($node);
if (isset($this->fullyQualifiedNameByHash[$uniqueHash])) {
return $this->fullyQualifiedNameByHash[$uniqueHash];
$uniqueId = $tag . \spl_object_id($node);
if (isset($this->fullyQualifiedNameByHash[$uniqueId])) {
return $this->fullyQualifiedNameByHash[$uniqueId];
}
$tag = \ltrim($tag, '@');
$uses = $this->useImportsResolver->resolve();
@ -54,7 +54,7 @@ final class ClassAnnotationMatcher
if ($fullyQualifiedClass === null) {
$fullyQualifiedClass = $tag;
}
$this->fullyQualifiedNameByHash[$uniqueHash] = $fullyQualifiedClass;
$this->fullyQualifiedNameByHash[$uniqueId] = $fullyQualifiedClass;
return $fullyQualifiedClass;
}
/**

View File

@ -16,9 +16,9 @@ final class CallableNodeVisitor extends NodeVisitorAbstract
*/
private $callable;
/**
* @var string|null
* @var int|null
*/
private $nodeHashToRemove;
private $nodeIdToRemove;
/**
* @param callable(Node $node): (int|Node|null) $callable
*/
@ -36,7 +36,7 @@ final class CallableNodeVisitor extends NodeVisitorAbstract
/** @var int|Node|null $newNode */
$newNode = $callable($node);
if ($newNode === NodeTraverser::REMOVE_NODE) {
$this->nodeHashToRemove = \spl_object_hash($originalNode);
$this->nodeIdToRemove = \spl_object_id($originalNode);
return $originalNode;
}
if ($originalNode instanceof Stmt && $newNode instanceof Expr) {
@ -49,8 +49,8 @@ final class CallableNodeVisitor extends NodeVisitorAbstract
*/
public function leaveNode(Node $node)
{
if ($this->nodeHashToRemove === \spl_object_hash($node)) {
$this->nodeHashToRemove = null;
if ($this->nodeIdToRemove === \spl_object_id($node)) {
$this->nodeIdToRemove = null;
return NodeTraverser::REMOVE_NODE;
}
return $node;

View File

@ -40,7 +40,7 @@ final class ConflictingNameResolver
*/
private $functionLikeManipulator;
/**
* @var array<string, string[]>
* @var array<int, string[]>
*/
private $conflictingVariableNamesByClassMethod = [];
public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNodeFinder, \Rector\Naming\Naming\ExpectedNameResolver $expectedNameResolver, MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver, FunctionLikeManipulator $functionLikeManipulator)
@ -82,16 +82,16 @@ final class ConflictingNameResolver
private function resolveConflictingVariableNamesForNew($functionLike) : array
{
// cache it!
$classMethodHash = \spl_object_hash($functionLike);
if (isset($this->conflictingVariableNamesByClassMethod[$classMethodHash])) {
return $this->conflictingVariableNamesByClassMethod[$classMethodHash];
$classMethodId = \spl_object_id($functionLike);
if (isset($this->conflictingVariableNamesByClassMethod[$classMethodId])) {
return $this->conflictingVariableNamesByClassMethod[$classMethodId];
}
$paramNames = $this->functionLikeManipulator->resolveParamNames($functionLike);
$newAssignNames = $this->resolveForNewAssigns($functionLike);
$nonNewAssignNames = $this->resolveForNonNewAssigns($functionLike);
$protectedNames = \array_merge($paramNames, $newAssignNames, $nonNewAssignNames);
$protectedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($protectedNames);
$this->conflictingVariableNamesByClassMethod[$classMethodHash] = $protectedNames;
$this->conflictingVariableNamesByClassMethod[$classMethodId] = $protectedNames;
return $protectedNames;
}
/**

View File

@ -30,7 +30,7 @@ final class OverridenExistingNamesResolver
*/
private $nodeNameResolver;
/**
* @var array<string, array<int, string>>
* @var array<int, array<int, string>>
*/
private $overridenExistingVariableNamesByClassMethod = [];
public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver)
@ -73,9 +73,9 @@ final class OverridenExistingNamesResolver
*/
private function resolveOveriddenNamesForNew($functionLike) : array
{
$classMethodHash = \spl_object_hash($functionLike);
if (isset($this->overridenExistingVariableNamesByClassMethod[$classMethodHash])) {
return $this->overridenExistingVariableNamesByClassMethod[$classMethodHash];
$classMethodId = \spl_object_id($functionLike);
if (isset($this->overridenExistingVariableNamesByClassMethod[$classMethodId])) {
return $this->overridenExistingVariableNamesByClassMethod[$classMethodId];
}
$currentlyUsedNames = [];
/** @var Assign[] $assigns */
@ -91,7 +91,7 @@ final class OverridenExistingNamesResolver
}
$currentlyUsedNames = \array_values($currentlyUsedNames);
$currentlyUsedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($currentlyUsedNames);
$this->overridenExistingVariableNamesByClassMethod[$classMethodHash] = $currentlyUsedNames;
$this->overridenExistingVariableNamesByClassMethod[$classMethodId] = $currentlyUsedNames;
return $currentlyUsedNames;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'c03fd2ad2625f1a0cf6a02d9875078b7114381ad';
public const PACKAGE_VERSION = 'd8d31debc51ab5df1d30655846bb0fbd9f76039b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-28 21:22:21';
public const RELEASE_DATE = '2023-08-29 00:39:22';
/**
* @var int
*/

View File

@ -22,7 +22,7 @@ final class ClassMethodAssignManipulator
*/
private $nodeNameResolver;
/**
* @var array<string, string[]>
* @var array<int, string[]>
*/
private $alreadyAddedClassMethodNames = [];
public function __construct(NodeFactory $nodeFactory, NodeNameResolver $nodeNameResolver)
@ -37,8 +37,8 @@ final class ClassMethodAssignManipulator
}
$classMethod->params[] = $this->nodeFactory->createParamFromNameAndType($name, $type);
$classMethod->stmts[] = new Expression($assign);
$classMethodHash = \spl_object_hash($classMethod);
$this->alreadyAddedClassMethodNames[$classMethodHash][] = $name;
$classMethodId = \spl_object_id($classMethod);
$this->alreadyAddedClassMethodNames[$classMethodId][] = $name;
}
private function hasMethodParameter(ClassMethod $classMethod, string $name) : bool
{
@ -47,10 +47,10 @@ final class ClassMethodAssignManipulator
return \true;
}
}
$classMethodHash = \spl_object_hash($classMethod);
if (!isset($this->alreadyAddedClassMethodNames[$classMethodHash])) {
$classMethodId = \spl_object_id($classMethod);
if (!isset($this->alreadyAddedClassMethodNames[$classMethodId])) {
return \false;
}
return \in_array($name, $this->alreadyAddedClassMethodNames[$classMethodHash], \true);
return \in_array($name, $this->alreadyAddedClassMethodNames[$classMethodId], \true);
}
}

View File

@ -109,7 +109,7 @@ CODE_SAMPLE;
*/
private $currentFileProvider;
/**
* @var array<string, Node[]>
* @var array<int, Node[]>
*/
private $nodesToReturn = [];
/**
@ -121,9 +121,9 @@ CODE_SAMPLE;
*/
private $rectorOutput;
/**
* @var string|null
* @var int|null
*/
private $toBeRemovedNodeHash;
private $toBeRemovedNodeId;
public function autowire(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, CurrentRectorProvider $currentRectorProvider, CurrentNodeProvider $currentNodeProvider, Skipper $skipper, ValueResolver $valueResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, CreatedByRuleDecorator $createdByRuleDecorator, ChangedNodeScopeRefresher $changedNodeScopeRefresher, RectorOutput $rectorOutput) : void
{
$this->nodeNameResolver = $nodeNameResolver;
@ -187,7 +187,7 @@ CODE_SAMPLE;
}
// @see NodeTraverser::* codes, e.g. removal of node of stopping the traversing
if ($refactoredNode === NodeTraverser::REMOVE_NODE) {
$this->toBeRemovedNodeHash = \spl_object_hash($originalNode);
$this->toBeRemovedNodeId = \spl_object_id($originalNode);
// notify this rule changing code
$rectorWithLineChange = new RectorWithLineChange(static::class, $originalNode->getLine());
$this->file->addRectorClassWithLine($rectorWithLineChange);
@ -224,12 +224,12 @@ CODE_SAMPLE;
if ($node->hasAttribute(AttributeKey::ORIGINAL_NODE)) {
return null;
}
$objectHash = \spl_object_hash($node);
if ($this->toBeRemovedNodeHash === $objectHash) {
$this->toBeRemovedNodeHash = null;
$objectId = \spl_object_id($node);
if ($this->toBeRemovedNodeId === $objectId) {
$this->toBeRemovedNodeId = null;
return NodeTraverser::REMOVE_NODE;
}
return $this->nodesToReturn[$objectHash] ?? $node;
return $this->nodesToReturn[$objectId] ?? $node;
}
protected function isName(Node $node, string $name) : bool
{
@ -313,9 +313,9 @@ CODE_SAMPLE;
$this->mirrorComments($firstNode, $originalNode);
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);
// search "infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown
$originalNodeHash = \spl_object_hash($originalNode);
$originalNodeId = \spl_object_id($originalNode);
// will be replaced in leaveNode() the original node must be passed
$this->nodesToReturn[$originalNodeHash] = $refactoredNode;
$this->nodesToReturn[$originalNodeId] = $refactoredNode;
return $originalNode;
}
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f
class ComposerAutoloaderInitc91db9ccbfaf98d91070b72dda598fcd
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitc91db9ccbfaf98d91070b72dda598fcd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitc91db9ccbfaf98d91070b72dda598fcd', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit129728a48b87039bca6f60cdcf06f91f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit129728a48b87039bca6f60cdcf06f91f::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd::$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 ComposerStaticInit129728a48b87039bca6f60cdcf06f91f
class ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2606,9 +2606,9 @@ class ComposerStaticInit129728a48b87039bca6f60cdcf06f91f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit129728a48b87039bca6f60cdcf06f91f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit129728a48b87039bca6f60cdcf06f91f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit129728a48b87039bca6f60cdcf06f91f::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd::$classMap;
}, null, ClassLoader::class);
}