Skip to content

Commit 91eb974

Browse files
committed
Move array_merge calls out of loops to improve performance
1 parent 50aecc2 commit 91eb974

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

DebugClassLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ private function setReturnType(string $types, string $class, string $method, str
800800
continue;
801801
}
802802

803-
$docTypes = array_merge($docTypes, $t);
803+
$docTypes[] = $t;
804804

805805
if ('mixed' === $n || 'void' === $n) {
806806
$nullable = false;
@@ -817,6 +817,7 @@ private function setReturnType(string $types, string $class, string $method, str
817817
$phpTypes[] = $n;
818818
}
819819
}
820+
$docTypes = array_merge([], ...$docTypes);
820821

821822
if (!$phpTypes) {
822823
return;

ErrorEnhancer/ClassNotFoundErrorEnhancer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ private function getClassCandidates(string $class): array
9393
if ($function[0] instanceof ClassLoader) {
9494
foreach ($function[0]->getPrefixes() as $prefix => $paths) {
9595
foreach ($paths as $path) {
96-
$classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
96+
$classes[] = $this->findClassInPath($path, $class, $prefix);
9797
}
9898
}
9999

100100
foreach ($function[0]->getPrefixesPsr4() as $prefix => $paths) {
101101
foreach ($paths as $path) {
102-
$classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
102+
$classes[] = $this->findClassInPath($path, $class, $prefix);
103103
}
104104
}
105105
}
106106
}
107107

108-
return array_unique($classes);
108+
return array_unique(array_merge([], ...$classes));
109109
}
110110

111111
private function findClassInPath(string $path, string $class, string $prefix): array

0 commit comments

Comments
 (0)