Skip to content

Commit

Permalink
Updated Rector to commit d8d31debc51ab5df1d30655846bb0fbd9f76039b
Browse files Browse the repository at this point in the history
rectorphp/rector-src@d8d31de [Performance] Use more performance spl_object_id() (#4876)
  • Loading branch information
TomasVotruba committed Aug 28, 2023
1 parent de9ddf6 commit 73a1ef4
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
12 changes: 6 additions & 6 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -90,9 +90,9 @@ public function createFromNodeOrEmpty(Node $node) : \Rector\BetterPhpDocParser\P
}
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);
Expand All @@ -111,7 +111,7 @@ public function createFromNode(Node $node) : ?\Rector\BetterPhpDocParser\PhpDocI
$this->setPositionOfLastToken($phpDocNode);
}
$phpDocInfo = $this->createFromPhpDocNode($phpDocNode, $tokenIterator, $node);
$this->phpDocInfosByObjectHash[$objectHash] = $phpDocInfo;
$this->phpDocInfosByObjectId[$objectId] = $phpDocInfo;
return $phpDocInfo;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public function __construct(UseImportNameMatcher $useImportNameMatcher, UseImpor
}
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();
$fullyQualifiedClass = $this->resolveFullyQualifiedClass($uses, $node, $tag, \false);
if ($fullyQualifiedClass === null) {
$fullyQualifiedClass = $tag;
}
$this->fullyQualifiedNameByHash[$uniqueHash] = $fullyQualifiedClass;
$this->fullyQualifiedNameByHash[$uniqueId] = $fullyQualifiedClass;
return $fullyQualifiedClass;
}
/**
Expand Down
10 changes: 5 additions & 5 deletions packages/PhpDocParser/NodeVisitor/CallableNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -36,7 +36,7 @@ public function enterNode(Node $node)
/** @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) {
Expand All @@ -49,8 +49,8 @@ public function enterNode(Node $node)
*/
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;
Expand Down
10 changes: 5 additions & 5 deletions rules/Naming/Naming/ConflictingNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -82,16 +82,16 @@ public function hasNameIsInFunctionLike(string $variableName, $functionLike) : b
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;
}
/**
Expand Down
10 changes: 5 additions & 5 deletions rules/Naming/Naming/OverridenExistingNamesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -73,9 +73,9 @@ public function hasNameInFunctionLikeForParam(string $expectedName, $classMethod
*/
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 */
Expand All @@ -91,7 +91,7 @@ private function resolveOveriddenNamesForNew($functionLike) : array
}
$currentlyUsedNames = \array_values($currentlyUsedNames);
$currentlyUsedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($currentlyUsedNames);
$this->overridenExistingVariableNamesByClassMethod[$classMethodHash] = $currentlyUsedNames;
$this->overridenExistingVariableNamesByClassMethod[$classMethodId] = $currentlyUsedNames;
return $currentlyUsedNames;
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 6 additions & 6 deletions src/NodeManipulator/ClassMethodAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,8 +37,8 @@ public function addParameterAndAssignToMethod(ClassMethod $classMethod, string $
}
$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
{
Expand All @@ -47,10 +47,10 @@ private function hasMethodParameter(ClassMethod $classMethod, string $name) : bo
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);
}
}
20 changes: 10 additions & 10 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter
*/
private $currentFileProvider;
/**
* @var array<string, Node[]>
* @var array<int, Node[]>
*/
private $nodesToReturn = [];
/**
Expand All @@ -121,9 +121,9 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter
*/
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;
Expand Down Expand Up @@ -187,7 +187,7 @@ public final function enterNode(Node $node)
}
// @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);
Expand Down Expand Up @@ -224,12 +224,12 @@ public function leaveNode(Node $node)
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
{
Expand Down Expand Up @@ -313,9 +313,9 @@ private function postRefactorProcess(Node $originalNode, Node $node, $refactored
$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);
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f::getLoader();
return ComposerAutoloaderInitc91db9ccbfaf98d91070b72dda598fcd::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit129728a48b87039bca6f60cdcf06f91f
class ComposerAutoloaderInitc91db9ccbfaf98d91070b72dda598fcd
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit129728a48b87039bca6f60cdcf06f91f
class ComposerStaticInitc91db9ccbfaf98d91070b72dda598fcd
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 73a1ef4

Please sign in to comment.