Skip to content

Commit

Permalink
[11.x] Optimize boostrap time by using hashtable to store providers (#…
Browse files Browse the repository at this point in the history
…51343)

* optimize boostrap time by using hashtable to store providers

* Update Application.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
sarven and taylorotwell committed May 21, 2024
1 parent ceb892a commit a01f53a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
/**
* All of the registered service providers.
*
* @var \Illuminate\Support\ServiceProvider[]
* @var array<string, \Illuminate\Support\ServiceProvider>
*/
protected $serviceProviders = [];

Expand Down Expand Up @@ -897,7 +897,9 @@ public function register($provider, $force = false)
*/
public function getProvider($provider)
{
return array_values($this->getProviders($provider))[0] ?? null;
$name = is_string($provider) ? $provider : get_class($provider);

return $this->serviceProviders[$name] ?? null;
}

/**
Expand Down Expand Up @@ -932,9 +934,11 @@ public function resolveProvider($provider)
*/
protected function markAsRegistered($provider)
{
$this->serviceProviders[] = $provider;
$class = get_class($provider);

$this->loadedProviders[get_class($provider)] = true;
$this->serviceProviders[$class] = $provider;

$this->loadedProviders[$class] = true;
}

/**
Expand Down Expand Up @@ -1388,7 +1392,7 @@ public function terminate()
/**
* Get the service providers that have been loaded.
*
* @return array
* @return array<string, boolean>
*/
public function getLoadedProviders()
{
Expand Down

0 comments on commit a01f53a

Please sign in to comment.