mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-14 15:12:23 +00:00
[DeadCode] Improve RemoveUnreachableStatementRector performance by return after array_splice early (#2193)
* [DeadCode] Improve RemoveUnreachableStatementRector by flag removed early on loop * fill, return early * use array_splice
This commit is contained in:
parent
c411410fa5
commit
4d7c087805
|
@ -120,7 +120,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function processCleanUpUnreachabelStmts(array $stmts): array
|
||||
{
|
||||
$originalStmts = $stmts;
|
||||
foreach ($stmts as $key => $stmt) {
|
||||
if (! isset($stmts[$key - 1])) {
|
||||
continue;
|
||||
|
@ -133,17 +132,12 @@ CODE_SAMPLE
|
|||
$previousStmt = $stmts[$key - 1];
|
||||
|
||||
if ($this->shouldRemove($previousStmt, $stmt)) {
|
||||
unset($stmts[$key]);
|
||||
break;
|
||||
array_splice($stmts, $key);
|
||||
return $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
if ($originalStmts === $stmts) {
|
||||
return $originalStmts;
|
||||
}
|
||||
|
||||
$stmts = array_values($stmts);
|
||||
return $this->processCleanUpUnreachabelStmts($stmts);
|
||||
return $stmts;
|
||||
}
|
||||
|
||||
private function shouldRemove(Stmt $previousStmt, Stmt $currentStmt): bool
|
||||
|
|
Loading…
Reference in New Issue
Block a user