From 731543cdc13692cd3d6ad561c73679672735156f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 14 Sep 2026 14:50:30 +0200 Subject: [PATCH] perf: Remove useless uses of array_shift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling array_shift in a loop is expensive for nothing, foreach is enough. Signed-off-by: Côme Chilliet --- .../Bootstrap/RegistrationContext.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 9b1e1efab24b9..83a483b1d4159 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -51,7 +51,6 @@ use Psr\Log\LoggerInterface; use RuntimeException; use Throwable; -use function array_shift; class RegistrationContext { /** @var ServiceRegistration[] */ @@ -731,7 +730,7 @@ public function registerGlobalScaleService(string $class): void { * @param App[] $apps */ public function delegateCapabilityRegistrations(array $apps): void { - while (($registration = array_shift($this->capabilities)) !== null) { + foreach ($this->capabilities as $registration) { $appId = $registration->getAppId(); if (!isset($apps[$appId])) { // If we land here something really isn't right. But at least we caught the @@ -752,13 +751,14 @@ public function delegateCapabilityRegistrations(array $apps): void { ]); } } + $this->capabilities = []; } /** * @param App[] $apps */ public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { - while (($registration = array_shift($this->crashReporters)) !== null) { + foreach ($this->crashReporters as $registration) { try { $registry->registerLazy($registration->getService()); } catch (Throwable $e) { @@ -768,10 +768,11 @@ public function delegateCrashReporterRegistrations(array $apps, Registry $regist ]); } } + $this->crashReporters = []; } public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void { - while (($panel = array_shift($this->dashboardPanels)) !== null) { + foreach ($this->dashboardPanels as $panel) { try { $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); } catch (Throwable $e) { @@ -781,10 +782,11 @@ public function delegateDashboardPanelRegistrations(IManager $dashboardManager): ]); } } + $this->dashboardPanels = []; } public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { - while (($registration = array_shift($this->eventListeners)) !== null) { + foreach ($this->eventListeners as $registration) { try { $eventDispatcher->addServiceListener( $registration->getEvent(), @@ -798,13 +800,14 @@ public function delegateEventListenerRegistrations(IEventDispatcher $eventDispat ]); } } + $this->eventListeners = []; } /** * @param App[] $apps */ public function delegateContainerRegistrations(array $apps): void { - while (($registration = array_shift($this->services)) !== null) { + foreach ($this->services as $registration) { $appId = $registration->getAppId(); if (!isset($apps[$appId])) { // If we land here something really isn't right. But at least we caught the @@ -832,8 +835,9 @@ public function delegateContainerRegistrations(array $apps): void { ]); } } + $this->services = []; - while (($registration = array_shift($this->aliases)) !== null) { + foreach ($this->aliases as $registration) { $appId = $registration->getAppId(); if (!isset($apps[$appId])) { // If we land here something really isn't right. But at least we caught the @@ -857,8 +861,9 @@ public function delegateContainerRegistrations(array $apps): void { ]); } } + $this->aliases = []; - while (($registration = array_shift($this->parameters)) !== null) { + foreach ($this->parameters as $registration) { $appId = $registration->getAppId(); if (!isset($apps[$appId])) { // If we land here something really isn't right. But at least we caught the @@ -882,6 +887,7 @@ public function delegateContainerRegistrations(array $apps): void { ]); } } + $this->parameters = []; } /**