Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'performance/sm-canonicalize-name-performance' of https:…
Browse files Browse the repository at this point in the history
  • Loading branch information
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ServiceManager implements ServiceLocatorInterface
*/
protected $throwExceptionInCreate = true;

/**
* @var array map of characters to be replaced through strtr
*/
protected $canonicalNamesReplacements = array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '');

/**
* @param ConfigInterface $config
*/
Expand Down Expand Up @@ -641,10 +646,12 @@ public function addPeeringServiceManager(ServiceManager $manager, $peering = sel
*/
protected function canonicalizeName($name)
{
if (!isset($this->canonicalNames[$name])) {
$this->canonicalNames[$name] = strtolower(str_replace(array('-', '_', ' ', '\\', '/'), '', $name));
if (isset($this->canonicalNames[$name])) {
return $this->canonicalNames[$name];
}
return $this->canonicalNames[$name];

// this is just for performance instead of using str_replace
return $this->canonicalNames[$name] = strtolower(strtr($name, $this->canonicalNamesReplacements));
}

/**
Expand Down

0 comments on commit 127fcbd

Please sign in to comment.