[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:
Abdul Malik Ikhsan 2022-04-29 13:34:03 +07:00 committed by GitHub
parent c411410fa5
commit 4d7c087805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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